Has anyone come across a problem whereby a parameter in the urn, :name, for example, contains a slash - either escaped (%2F) or not (/) that causes the route to be incorrectly recognised? I have the following route: "climbs/:id/:name/:action", :action => ''show'', :id => /(\d*)/ If the :name part contains a slash, the route is not followed. If anyone else has seen this, I''d love to know how you sorted it! Thanks, Matt --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Alex, Thanks for replying - it''s a bit of a bind, this one! The name part is specified by the users, so it''s not possible to guarantee that it will always or never contain a slash. I was hoping that %2F would be interpreted by routing as being part of a parameter, whereas a literal / would be interpreted as a separator. I''m sure this has been solved by someone somewhere - how would a rails- based blog cope with a post that contains a slash in the title, for example? Thanks again. On 21 Feb, 22:53, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Matt Hall wrote: > > Has anyone come across a problem whereby a parameter in the > > urn, :name, for example, contains aslash- either escaped (%2F) or > > not (/) that causes the route to be incorrectly recognised? > > > I have the following route: > > > "climbs/:id/:name/:action", :action => ''show'', :id => /(\d*)/ > > > If the :name part contains aslash, the route is not followed. If > > anyone else has seen this, I''d love to know how you sorted it! > > > Thanks, > > > Matt > > / is considered a separator character by the routing engine. That is > how it divides params. > > I know you can get around this with the "." character by using a > requirement regex. So maybe you can do the same with the "/" > > "climbs/:id/:name/:action", :action => ''show'', :id => /(\d*)/, > :name => %r{/?} > > It may not work though. With this regex it will probably always > interpret the :action as part of the :name unless :name always had aslashin it. > > You sure you wouldn;t be better off with a ''-'' instead of a ''/'' in that > :name? > > -- > Posted viahttp://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Hall wrote:> Hi Alex,> I''m sure this has been solved by someone somewhere - how would a rails- > based blog cope with a post that contains a slash in the title, for > example? > > Thanks again.I''d have thought that it wouldn''t. Since as a separator / is part of the URL spec, I think it''s just not going to work. You can encoide slashes as part of the query string, but not (I''d have thought) as part of the URL... any URL, not just rails. My suggestion would be to just not allow slashes as part of the name, or replace them with ''-'' when used as part of the url....which is what usually happens when a permalink is generated from a post name. Alan -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So the solution would be to create a slug column in any table that allows data from a column that contains slashes or periods (same problem with periods in rails >= 1.2) - the slug column containing an appropriately escaped value of the column to be referenced in the URL. I''ll give this a try. Thanks for your help! On 22 Feb, 15:12, Alan Francis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Matt Hall wrote: > > Hi Alex, > > I''m sure this has been solved by someone somewhere - how would a rails- > > based blog cope with a post that contains a slash in the title, for > > example? > > > Thanks again. > > I''d have thought that it wouldn''t. Since as a separator / is part of > the URL spec, I think it''s just not going to work. You can encoide > slashes as part of the query string, but not (I''d have thought) as part > of the URL... any URL, not just rails. > > My suggestion would be to just not allow slashes as part of the name, or > replace them with ''-'' when used as part of the url....which is what > usually happens when a permalink is generated from a post name. > > Alan > > -- > Posted viahttp://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Hall wrote:> So the solution would be to create a slug column in any table that > allows data from a column that contains slashes or periods (same > problem with periods in rails >= 1.2) - the slug column containing an > appropriately escaped value of the column to be referenced in the URL. > > I''ll give this a try. > > Thanks for your help! > > On 22 Feb, 15:12, Alan Francis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Either that or do the substitution on the fly (both on the way out and the way in). A. -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Hall wrote:> Has anyone come across a problem whereby a parameter in the > urn, :name, for example, contains a slash - either escaped (%2F) or > not (/) that causes the route to be incorrectly recognised? > > I have the following route: > > "climbs/:id/:name/:action", :action => ''show'', :id => /(\d*)/ > > If the :name part contains a slash, the route is not followed. If > anyone else has seen this, I''d love to know how you sorted it! > > Thanks, > > > MattI just have the same problem. to solve it, i encode the parameter put in the controller header : require ''cgi'' before send encode parameter : CGI::escape(params[:name]) at reception decode it : CGI::unescape(params[:name]) Then, you''ll keep valid url :) -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---