Hello to all, I''m confronted to a quite simple problem (I hope so): In a rhtml file I''m using the following code to make a select from a act_as_tree Model: <%= select_tag("input_region", options_for_select(Region.find(:all, :order => "name").collect {|c| [ " " * c.ancestors.size + c.name, c.id ]})) %> But the generated output is: <select id="input_region" name="input_region"> <option value="4">&nbsp;Asia </option> <option value="7">&nbsp;Australia</option> <option value="2">&nbsp;Europe</option> <option value="3">&nbsp;&nbsp;France</option> <option value="5">&nbsp;North America</option> <option value="6">&nbsp;South America</option> <option value="1">World</option></select> As you can see the is converted to escape html special chars( => &nsbp;). How can I prevent rails to convert html chars ? Thx in advance for your answers. ++ Jerome -- 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 -~----------~----~----~----~------~----~------~--~---
Jerome: What happens if you use a single space: '' '' instead of ? Does it convert the space to ? -Anthony On Sep 7, 2006, at 10:48 AM, Jérôme Fat wrote:> > Hello to all, > > I''m confronted to a quite simple problem (I hope so): > > In a rhtml file I''m using the following code to make a select from a > act_as_tree Model: > > <%= select_tag("input_region", options_for_select(Region.find > (:all, > :order => "name").collect {|c| [ " " * c.ancestors.size + c.name, > c.id ]})) %> > > But the generated output is: > <select id="input_region" name="input_region"> > <option value="4">&nbsp;Asia </option> > <option value="7">&nbsp;Australia</option> > <option value="2">&nbsp;Europe</option> > <option value="3">&nbsp;&nbsp;France</option> > <option value="5">&nbsp;North America</option> > <option value="6">&nbsp;South America</option> > <option value="1">World</option></select> > > > As you can see the is converted to escape html special > chars( => &nsbp;). How can I prevent rails to convert html > chars ? > > Thx in advance for your answers. > > ++ Jerome > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Anthony Carlos wrote:> Jerome: > > What happens if you use a single space: '' '' instead of ? Does > it convert the space to ? > > -AnthonyIf I use '' '' instead of '' '', '' '' is not converted into '' ''. Only HTML spécial chars are converted (& > < and so ...) I think the string is passing through the h funtion. I don''t know how to prevent it. I could rewrite de options_for_select but I''m pretty sure there''s an alternative. Thx -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Nobody has an answer to this problem ? -- 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 -~----------~----~----~----~------~----~------~--~---
Jérôme (fat) wrote:> Nobody has an answer to this problem ? > >Wow, you young whippersnappers these days have no patience eh :P :P (that is a joke for the humour impaired). Apparently, the html_escape code in Rails/Erb/Most projects I have ever seen, assumes (rightly or wrongly) that your input will NOT have ANY markup''s already converted inside it. The trick is to make the html_escape somewhat more tolerant. The code I would suggest would be something like this; irb(main):014:0> s="this is test" => "this is test" irb(main):015:0> s.gsub(/(&+(?!amp;))/,"&") => "this is &nbsp; test" irb(main):016:0> s.gsub(/(&+(?!amp;)(?!lt;)(?!gt;)(?!quot;)(?!nbsp;))/,"&") => "this is test" Of course, you probably want to fling that into an ''override'' for your application (eg; application.rb) something along the lines of; def html_escape(s) s.to_s.gsub(/(&+(?!amp;)(?!lt;)(?!gt;)(?!quot;)(?!nbsp;))/,"&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<") end I assume that if you fling it in there, everything will be good with the world. You may have to deal with re-declaring the alias and the module_functions again, no idea. Take with a pinch of salt (or vinegar if your that perverse). Hopefully you get the idea. You could always update the erb.rb file that I believe is the main ''culprit'', and you could submit a patch to the Erb maintainer. You get the idea, share the wealth etc etc :) Sorry for the rambling incoherent-ness of this message, I have only had my second cup of coffee so far :) Regards Stef --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Stef Telford wrote:> Jérôme (fat) wrote: > >> Nobody has an answer to this problem ? >> >> >> > > Wow, you young whippersnappers these days have no patience eh :P :P > (that is a joke for the humour impaired). > > Apparently, the html_escape code in Rails/Erb/Most projects I have ever > seen, assumes (rightly or wrongly) that your input will NOT have ANY > markup''s already converted inside it. The trick is to make the > html_escape somewhat more tolerant. The code I would suggest would be > something like this; > > irb(main):014:0> s="this is test" > => "this is test" > irb(main):015:0> s.gsub(/(&+(?!amp;))/,"&") > => "this is &nbsp; test" > irb(main):016:0> > s.gsub(/(&+(?!amp;)(?!lt;)(?!gt;)(?!quot;)(?!nbsp;))/,"&") > => "this is test" > > Of course, you probably want to fling that into an ''override'' for your > application (eg; application.rb) something along the lines of; > > def html_escape(s) > > s.to_s.gsub(/(&+(?!amp;)(?!lt;)(?!gt;)(?!quot;)(?!nbsp;))/,"&").gsub(/\"/, > """).gsub(/>/, ">").gsub(/</, "<") > end > > I assume that if you fling it in there, everything will be good with the > world. You may have to deal with re-declaring the alias and the > module_functions again, no idea. Take with a pinch of salt (or vinegar > if your that perverse). Hopefully you get the idea. > > You could always update the erb.rb file that I believe is the main > ''culprit'', and you could submit a patch to the Erb maintainer. You get > the idea, share the wealth etc etc :) > > Sorry for the rambling incoherent-ness of this message, I have only had > my second cup of coffee so far :) > Regards > Stef > > > > > > > >You could try this... require ''cgi'' def htmlarize(str) CGI.unescapeHTML(str) end and do something like: <%=htmlarize( select_tag("input_region", options_for_select(Region.find(:all, :order => "name").collect {|c| [ " " * c.ancestors.size + c.name, c.id ]})) )%> Something like that might work? Gustav Paul gustav-PUm+PnBUKx7YkQIYctQFYw@public.gmane.org itsdEx.com -- about me: My greatest achievement was when all the other kids just learnt to count from 1 to 10, i was counting (0..9) - gustav.paul --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> You could try this... > > require ''cgi'' > def htmlarize(str) > CGI.unescapeHTML(str) > end > > and do something like: > > <%=htmlarize( > > select_tag("input_region", options_for_select(Region.find(:all, > :order => "name").collect {|c| [ " " * c.ancestors.size + c.name, > c.id ]})) > > )%> > > Something like that might work?Thanks you very much, it works like a charm. ++ Jerome -- 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 -~----------~----~----~----~------~----~------~--~---