I have the below link I am generating and type.name returns some strings with a forward slash ("/"). This of course messes up routing. I would like to escape it to %2F however I am unclear on how to do that. <%= link_to type.name, types_path(CGI::escape(type.name)) %> If I do the below. it gives a no route error. <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> Thanks. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hi, have a try: <%= link_to type.name, "#{types_path(type.name)}" %> keep the second parameter is string,right? 2011/5/21 tashfeen.ekram <tashfeen.ekram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> I have the below link I am generating and type.name returns some > strings with a forward slash ("/"). This of course messes up routing. > I would like to escape it to %2F however I am unclear on how to do > that. > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > If I do the below. it gives a no route error. > > <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> > > Thanks. > > -- > 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 this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Deshi Xiao Twitter: xds2000 E-mail: xiaods(AT)gmail.com -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
That is did not seem to work. I got a routing error. <%= link_to CGI::escape(type.name), types_path(CGI::escape(type.name)) %> The name of the link is appropriately displayed with the "/" replaced but the link is not. On May 22, 12:14 am, tommy xiao <xia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, have a try: > <%= link_to type.name, "#{types_path(type.name)}" %> > > keep the second parameter is string,right? > > 2011/5/21 tashfeen.ekram <tashfeen.ek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > > > > > > > I have the below link I am generating and type.name returns some > > strings with a forward slash ("/"). This of course messes up routing. > > I would like to escape it to %2F however I am unclear on how to do > > that. > > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > > If I do the below. it gives a no route error. > > > <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> > > > Thanks. > > > -- > > 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 this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > Deshi Xiao > Twitter: xds2000 > E-mail: xiaods(AT)gmail.com-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Friday, May 20, 2011 4:48:17 PM UTC-6, tashfeen.ekram wrote:> > I have the below link I am generating and type.name returns some > strings with a forward slash ("/"). This of course messes up routing. > I would like to escape it to %2F however I am unclear on how to do > that. > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > If I do the below. it gives a no route error. > > <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> > > Thanks. > >The #types_path method is an auto-generated "named routes" helper (at least I''m assuming it is based on its name and how you''re using it). If you nave a resource route such as: "resources :types" in your config/routes.rb then the #types_path helper doesn''t need any arguments and takes you to the index action on the TypesController. So, if my assumptions are right and the index action is what you''re trying to link to, then the following should be sufficient: <%= link_to type.name, types_path %> However, if you''re trying to link to a specific instance (which it kind of looks like you intend to) then you''d instead use: <%= link_to type.name, type_path(type) %> Anyhow, update us on whether these assumptions are correct or not if you''re still having problems. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
actually, it is not a resource route. it is a route that is specifically defined. that is there is not resource "type." match "/types/:types" => "browse#list", :as => :types It is unresourceful route. On May 23, 4:27 pm, Kendall Gifford <zettab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Friday, May 20, 2011 4:48:17 PM UTC-6, tashfeen.ekram wrote: > > > I have the below link I am generating and type.name returns some > > strings with a forward slash ("/"). This of course messes up routing. > > I would like to escape it to %2F however I am unclear on how to do > > that. > > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > > If I do the below. it gives a no route error. > > > <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> > > > Thanks. > > The #types_path method is an auto-generated "named routes" helper (at least > I''m assuming it is based on its name and how you''re using it). If you nave a > resource route such as: "resources :types" in your config/routes.rb then the > #types_path helper doesn''t need any arguments and takes you to the index > action on the TypesController. So, if my assumptions are right and the index > action is what you''re trying to link to, then the following should be > sufficient: > > <%= link_to type.name, types_path %> > > However, if you''re trying to link to a specific instance (which it kind of > looks like you intend to) then you''d instead use: > > <%= link_to type.name, type_path(type) %> > > Anyhow, update us on whether these assumptions are correct or not if you''re > still having problems.-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Friday, May 27, 2011 3:41:00 PM UTC-6, tashfeen.ekram wrote:> > actually, it is not a resource route. it is a route that is > specifically defined. that is there is not resource "type." > > match "/types/:types" => "browse#list", :as => :types > > It is unresourceful route. > >If this is your route, as long as you don''t have other routes that begin with "/types/..." then you could update it with a constraint that allows forward slashes:> match "/types/:types" => "browse#list", :types => /.*/, :as => :typesThis should both make the routes match correctly on incoming URLs _and_ allow you to call: types_path("text/with/slashes") without any errors being raised. Of course, you should adjust the constraints regexp as is appropriate (I find it ugly/hackish to have it wide open like that except where it would truly make sense). Also, if you had other routes like:> match "/types/sub/directory/:id" => "browse#yourmom", :as => :your_momThen it''d conflict using the wide-open constraint technique. Anyhow, if you absolutely insist on simply escaping slashes instead of adding a constraint to your route, what was wrong with your first, original example:> <%= link_to type.name, types_path(CGI::escape(type.name)) %>You mentioned the second one gave a "no route" error, but did this one? (I just did a quick test and this actually worked for me). Just curious. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<%= link_to type.name, types_path(CGI::escape(type.name)) %> The above one renders the page fine. However, when I click on the link, then it gives me the no route error. <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> The one above does not even render the page and gives me the below error: No route matches {:controller=>"xxx", :types=>"yyy/ yyy", :action=>"zzz"} On May 27, 8:46 pm, Kendall Gifford <zettab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Friday, May 27, 2011 3:41:00 PM UTC-6, tashfeen.ekram wrote: > > > actually, it is not a resource route. it is a route that is > > specifically defined. that is there is not resource "type." > > > match "/types/:types" => "browse#list", :as => :types > > > It is unresourceful route. > > If this is your route, as long as you don''t have other routes that begin > with "/types/..." then you could update it with a constraint that allows > forward slashes: > > > match "/types/:types" => "browse#list", :types => /.*/, :as => :types > > This should both make the routes match correctly on incoming URLs _and_ > allow you to call: types_path("text/with/slashes") without any errors being > raised. > > Of course, you should adjust the constraints regexp as is appropriate (I > find it ugly/hackish to have it wide open like that except where it would > truly make sense). Also, if you had other routes like: > > > match "/types/sub/directory/:id" => "browse#yourmom", :as => :your_mom > > Then it''d conflict using the wide-open constraint technique. > > Anyhow, if you absolutely insist on simply escaping slashes instead of > adding a constraint to your route, what was wrong with your first, original > example: > > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > You mentioned the second one gave a "no route" error, but did this one? (I > just did a quick test and this actually worked for me). Just curious.-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Also, I noticed that even spaces are not being escaped with the below: <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> The link is rendered with a space in it. Once I click on it, it is eventually rerouted to the same address except with the space escaped with a %20. That does not seem like the intended behavior? On May 27, 8:46 pm, Kendall Gifford <zettab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Friday, May 27, 2011 3:41:00 PM UTC-6, tashfeen.ekram wrote: > > > actually, it is not a resource route. it is a route that is > > specifically defined. that is there is not resource "type." > > > match "/types/:types" => "browse#list", :as => :types > > > It is unresourceful route. > > If this is your route, as long as you don''t have other routes that begin > with "/types/..." then you could update it with a constraint that allows > forward slashes: > > > match "/types/:types" => "browse#list", :types => /.*/, :as => :types > > This should both make the routes match correctly on incoming URLs _and_ > allow you to call: types_path("text/with/slashes") without any errors being > raised. > > Of course, you should adjust the constraints regexp as is appropriate (I > find it ugly/hackish to have it wide open like that except where it would > truly make sense). Also, if you had other routes like: > > > match "/types/sub/directory/:id" => "browse#yourmom", :as => :your_mom > > Then it''d conflict using the wide-open constraint technique. > > Anyhow, if you absolutely insist on simply escaping slashes instead of > adding a constraint to your route, what was wrong with your first, original > example: > > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > You mentioned the second one gave a "no route" error, but did this one? (I > just did a quick test and this actually worked for me). Just curious.-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
In both of the below, the explicit escaped back slash "%2F" is converted to an actual backslash. <%= link_to "blah", types_path("Vits%2Fmins") %> <%= link_to "blah", :controller => :browse, :action => :list, :types => "Vits%2Fmins" %> Is this a safety feature of the link_to helper? On Jun 8, 9:16 pm, "tashfeen.ekram" <tashfeen.ek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Also, I noticed that even spaces are not being escaped with the below: > <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> > > The link is rendered with a space in it. Once I click on it, it is > eventually rerouted to the same address except with the space escaped > with a %20. That does not seem like the intended behavior? > > On May 27, 8:46 pm, Kendall Gifford <zettab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > On Friday, May 27, 2011 3:41:00 PM UTC-6,tashfeen.ekram wrote: > > > > actually, it is not a resource route. it is a route that is > > > specifically defined. that is there is not resource "type." > > > > match "/types/:types" => "browse#list", :as => :types > > > > It is unresourceful route. > > > If this is your route, as long as you don''t have other routes that begin > > with "/types/..." then you could update it with a constraint that allows > > forward slashes: > > > > match "/types/:types" => "browse#list", :types => /.*/, :as => :types > > > This should both make the routes match correctly on incoming URLs _and_ > > allow you to call: types_path("text/with/slashes") without any errors being > > raised. > > > Of course, you should adjust the constraints regexp as is appropriate (I > > find it ugly/hackish to have it wide open like that except where it would > > truly make sense). Also, if you had other routes like: > > > > match "/types/sub/directory/:id" => "browse#yourmom", :as => :your_mom > > > Then it''d conflict using the wide-open constraint technique. > > > Anyhow, if you absolutely insist on simply escaping slashes instead of > > adding a constraint to your route, what was wrong with your first, original > > example: > > > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > > You mentioned the second one gave a "no route" error, but did this one? (I > > just did a quick test and this actually worked for me). Just curious.-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Even the below does the same thing: <%= link_to "blah", "/types/Vits%2Fmins" %> On Jun 9, 10:42 pm, "tashfeen.ekram" <tashfeen.ek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In both of the below, the explicit escaped back slash "%2F" is > converted to an actual backslash. > > <%= link_to "blah", types_path("Vits%2Fmins") %> > <%= link_to "blah", :controller => :browse, :action => :list, :types > => "Vits%2Fmins" %> > > Is this a safety feature of the link_to helper? > > On Jun 8, 9:16 pm, "tashfeen.ekram" <tashfeen.ek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Also, I noticed that even spaces are not being escaped with the below: > > <%= link_to type.name, types_path(CGI::escapeHTML(type.name)) %> > > > The link is rendered with a space in it. Once I click on it, it is > > eventually rerouted to the same address except with the space escaped > > with a %20. That does not seem like the intended behavior? > > > On May 27, 8:46 pm, Kendall Gifford <zettab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Friday, May 27, 2011 3:41:00 PM UTC-6,tashfeen.ekram wrote: > > > > > actually, it is not a resource route. it is a route that is > > > > specifically defined. that is there is not resource "type." > > > > > match "/types/:types" => "browse#list", :as => :types > > > > > It is unresourceful route. > > > > If this is your route, as long as you don''t have other routes that begin > > > with "/types/..." then you could update it with a constraint that allows > > > forward slashes: > > > > > match "/types/:types" => "browse#list", :types => /.*/, :as => :types > > > > This should both make the routes match correctly on incoming URLs _and_ > > > allow you to call: types_path("text/with/slashes") without any errors being > > > raised. > > > > Of course, you should adjust the constraints regexp as is appropriate (I > > > find it ugly/hackish to have it wide open like that except where it would > > > truly make sense). Also, if you had other routes like: > > > > > match "/types/sub/directory/:id" => "browse#yourmom", :as => :your_mom > > > > Then it''d conflict using the wide-open constraint technique. > > > > Anyhow, if you absolutely insist on simply escaping slashes instead of > > > adding a constraint to your route, what was wrong with your first, original > > > example: > > > > > <%= link_to type.name, types_path(CGI::escape(type.name)) %> > > > > You mentioned the second one gave a "no route" error, but did this one? (I > > > just did a quick test and this actually worked for me). Just curious.-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.