Hi! I need to redirect to some 3rd party websites. The issue is that some of the urls works to redirect and some doesn''t work, using redirect_to url Example 1: http://example.com/click?a(9999999)p(9999999)prod(999999)ttid(999)url(http%3A%2F%2Fwww.someothersite.se%2Fd%2FBLah-Fooo%2FBar%2F_%2FA-3z324qaF1z140nu%3FNr%3D234234234) With this URL I just do: redirect_to url Example 2: http://click.example.com/c/9999/m/9999/t/a/9999/?url=http://www.someothersite.se/sv/foo/bar/baz-99/foo-bar-baz-9999?tm=999999 When using: redirect_to url I get "ERROR URI::InvalidURIError: bad URI(is not URI?)" So, I tried to just do: redirect_to URI.encode(url) ... and it works! But then the URL in example 1 is not working anymore. Says the site is not found. No error in Rails though. So, I need an approach that works with both (all?) URIs. Any ideas? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/7c36X7qIFtsJ. For more options, visit https://groups.google.com/groups/opt_out.
On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson <linus.pettersson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to redirect to some 3rd party websites. The issue is that some of the > urls works to redirect and some doesn''t work, using redirect_to url> So, I need an approach that works with both (all?) URIs. Any ideas?Write a utility method, e.g. redirect_to sanity_checked(url) that either returns the original URL if it''s good or an encoded version if not. Which is not to say that simply encoding it will fix every error, so it''s probably worth checking that result too :-) HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Thank you for your time. How can I check if the URL is "good" or needs to be encoded? Best Regards Linus Den söndagen den 29:e juli 2012 kl. 19:30:58 UTC+2 skrev Hassan Schroeder:> > On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson> wrote: > > > I need to redirect to some 3rd party websites. The issue is that some of > the > > urls works to redirect and some doesn''t work, using redirect_to url > > > So, I need an approach that works with both (all?) URIs. Any ideas? > > Write a utility method, e.g. redirect_to sanity_checked(url) that either > returns the original URL if it''s good or an encoded version if not. > > Which is not to say that simply encoding it will fix every error, so it''s > probably worth checking that result too :-) > > HTH, > -- > Hassan Schroeder ---------------------- > http://about.me/hassanschroeder > twitter: @hassan >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/XDdZsyFrpwkJ. For more options, visit https://groups.google.com/groups/opt_out.
I mean, URI.parse(uri) doesn''t return any error on either of the URIs it seems. Den söndagen den 29:e juli 2012 kl. 19:44:48 UTC+2 skrev Linus Pettersson:> > Thank you for your time. > > How can I check if the URL is "good" or needs to be encoded? > > Best Regards > Linus > > > Den söndagen den 29:e juli 2012 kl. 19:30:58 UTC+2 skrev Hassan Schroeder: >> >> On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson > > > wrote: >> >> > I need to redirect to some 3rd party websites. The issue is that some >> of the >> > urls works to redirect and some doesn''t work, using redirect_to url >> >> > So, I need an approach that works with both (all?) URIs. Any ideas? >> >> Write a utility method, e.g. redirect_to sanity_checked(url) that either >> returns the original URL if it''s good or an encoded version if not. >> >> Which is not to say that simply encoding it will fix every error, so it''s >> probably worth checking that result too :-) >> >> HTH, >> -- >> Hassan Schroeder ---------------------- >> http://about.me/hassanschroeder >> twitter: @hassan >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/R5v4pDnE-jcJ. For more options, visit https://groups.google.com/groups/opt_out.
Actually, I think I found a solution now. I first parse it, like: uri = URI.parse(the_url) and then: redirect_to uri.to_s Works :) Den söndagen den 29:e juli 2012 kl. 19:30:58 UTC+2 skrev Hassan Schroeder:> > On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson > wrote: > > > I need to redirect to some 3rd party websites. The issue is that some of > the > > urls works to redirect and some doesn''t work, using redirect_to url > > > So, I need an approach that works with both (all?) URIs. Any ideas? > > Write a utility method, e.g. redirect_to sanity_checked(url) that either > returns the original URL if it''s good or an encoded version if not. > > Which is not to say that simply encoding it will fix every error, so it''s > probably worth checking that result too :-) > > HTH, > -- > Hassan Schroeder ------------------------ > http://about.me/hassanschroeder > twitter: @hassan >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/gE8jCcdI50EJ. For more options, visit https://groups.google.com/groups/opt_out.
My bad, it does NOT work! Den söndagen den 29:e juli 2012 kl. 20:04:14 UTC+2 skrev Linus Pettersson:> > Actually, I think I found a solution now. > > I first parse it, like: > uri = URI.parse(the_url) > and then: > redirect_to uri.to_s > > > Works :) > > > Den söndagen den 29:e juli 2012 kl. 19:30:58 UTC+2 skrev Hassan Schroeder: >> >> On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson >> wrote: >> >> > I need to redirect to some 3rd party websites. The issue is that some >> of the >> > urls works to redirect and some doesn''t work, using redirect_to url >> >> > So, I need an approach that works with both (all?) URIs. Any ideas? >> >> Write a utility method, e.g. redirect_to sanity_checked(url) that either >> returns the original URL if it''s good or an encoded version if not. >> >> Which is not to say that simply encoding it will fix every error, so it''s >> probably worth checking that result too :-) >> >> HTH, >> -- >> Hassan Schroeder ------------------------ >> http://about.me/hassanschroeder >> twitter: @hassan >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/qnDplKzfktEJ. For more options, visit https://groups.google.com/groups/opt_out.
On Sun, Jul 29, 2012 at 10:53 AM, Linus Pettersson <linus.pettersson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I mean, URI.parse(uri) doesn''t return any error on either of the URIs it > seems.Without looking at the code, it''s hard to imagine you''re getting the "ERROR URI::InvalidURIError: bad URI(is not URI?)" exception you originally reported from other than URI.parse, but -- can you get a stack trace to show exactly what''s raising that? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.