jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-27 14:25 UTC
format a string in params
Hi, i''ve got a problem with slashes "/" : i do a redirect : redirect_to :action => action, :id => params[:my_param] but when parameter string params[:my_param] is with slash, for example "16/9", i''ve got the following error no route found to match "/controller/action/16/9" with {:method=>:get} does anybody know a function to format that kind of parameter to get a valid url? --~--~---------~--~----~------------~-------~--~----~ 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, what does 16/9 represent? In any case, you''ll need to sanitize, params[:my_param], before you redirect. Good luck, -Conrad On 2/27/07, jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > i''ve got a problem with slashes "/" : > i do a redirect : > > redirect_to :action => action, :id => params[:my_param] > > but when parameter string params[:my_param] is with slash, for example > "16/9", i''ve got the following error > > no route found to match "/controller/action/16/9" with {:method=>:get} > > does anybody know a function to format that kind of parameter to get a > valid url? > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-27 15:43 UTC
Re: format a string in params
Thank you for your answer. I''ve found a solution : encode parameter. put in the controller header : require ''cgi'' before send encode parameter : CGI::escape(params[:my_param]) at reception decode it : CGI::unescape(params[:my_param]) Then, i keep valid url :) On 27 fév, 15:38, "Conrad Taylor" <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, what does 16/9 represent? In any case, you''ll need to sanitize, > params[:my_param], before you redirect. > > Good luck, > > -Conrad > > On 2/27/07, jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > i''ve got a problem with slashes "/" : > > i do a redirect : > > > redirect_to :action => action, :id => params[:my_param] > > > but when parameter string params[:my_param] is with slash, for example > > "16/9", i''ve got the following error > > > no route found to match "/controller/action/16/9" with {:method=>:get} > > > does anybody know a function to format that kind of parameter to get a > > valid url?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-27 16:06 UTC
Re: format a string in params
You don''t need to use the CGI escape, Rails gives you the same thing, it is called h (alias for html_escape) that does the same thing. On Feb 27, 10:43 am, "jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you for your answer. >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> You don''t need to use the CGI escape, Rails gives you the same thing, > it is called h (alias for html_escape) that does the same thing.URL encoding is NOT the same thing as HTML escaping. I don''t see h() in the api docs, but I''m pretty sure it would leave "/" alone since it doesn''t need to be escaped in HTML. -- 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 -~----------~----~----~----~------~----~------~--~---
jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-27 16:25 UTC
Re: format a string in params
No, html_escape as the same means translate html. To translate url we have to use url_encode : http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.html but i didn''t find the way to decode it.... On 27 fév, 17:06, "bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You don''t need to use the CGI escape, Rails gives you the same thing, > it is called h (alias for html_escape) that does the same thing. > > On Feb 27, 10:43 am, "jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thank you for your answer.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-27 16:27 UTC
Re: format a string in params
Sorry mark i''ve posted my message at the same time you did On 27 fév, 17:21, Mark Thomas <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > You don''t need to use the CGI escape, Rails gives you the same thing, > > it is called h (alias for html_escape) that does the same thing. > > URL encoding is NOT the same thing as HTML escaping. I don''t see h() in > the api docs, but I''m pretty sure it would leave "/" alone since it > doesn''t need to be escaped in HTML. > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> No, html_escape as the same means translate html. > To translate url we have to use url_encode :http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.htmlAh, the u() method, a counterpart to h().> but i didn''t find the way to decode it....Rails decodes URLs automatically. However, if for some reason you needed to do this yourself: def url_decode(str) str.to_s.gsub(/%([A-F\d]{2})/in) { [$1.hex].pack(''C'') } end - Mark. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-28 19:35 UTC
Re: format a string in params
thank you On Feb 27, 9:13 pm, "Mark Thomas" <m...-gkTqyYPWbQbz1n+OaKNE4w@public.gmane.org> wrote:> > No, html_escape as the same means translate html. > > To translate url we have to use url_encode :http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.html > > Ah, the u() method, a counterpart to h(). > > > but i didn''t find the way to decode it.... > > Rails decodes URLs automatically. However, if for some reason you > needed to do this yourself: > > def url_decode(str) > str.to_s.gsub(/%([A-F\d]{2})/in) { [$1.hex].pack(''C'') } > end > > - Mark.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---