In one of my views I have this code: <%=content_tag :h2, :header do-%> <%=yield(:page_title).html_safe?-%> <%=yield(:page_title).titleize-%> <%- end -%> Which displays: true A Boy &Amp; His Dog However this code: <%=content_tag :h2, :header do-%> <%=yield(:page_title).html_safe?-%> <%=yield(:page_title).capitalize-%> <%- end -%> displays: true A boy & his dog Is this behaviour of titleize intentional? I want to titleize ''a dog & his boy'' and preserve the & character in the final display. -- 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-/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.
On 7 Mar 2011, at 17:42, James Byrne <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In one of my views I have this code: > > <%=content_tag :h2, :header do-%> > <%=yield(:page_title).html_safe?-%> > <%=yield(:page_title).titleize-%> > <%- end -%> >What exactly does yield(:page_title) return before you titleize it? Fred> Which displays: > > true A Boy &Amp; His Dog > > However this code: > > > <%=content_tag :h2, :header do-%> > <%=yield(:page_title).html_safe?-%> > <%=yield(:page_title).capitalize-%> > <%- end -%> > > displays: > > true A boy & his dog > > Is this behaviour of titleize intentional? I want to titleize ''a dog & > his boy'' and preserve the & character in the final display. > > -- > 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-/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. >-- 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.
Frederick Cheung wrote in post #986019:> On 7 Mar 2011, at 17:42, James Byrne <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> In one of my views I have this code: >> >> <%=content_tag :h2, :header do-%> >> <%=yield(:page_title).html_safe?-%> >> <%=yield(:page_title).titleize-%> >> <%- end -%> >> > > What exactly does yield(:page_title) return before you titleize it? > > Fred<%-content_for :page_title, "a boy & his dog" -%> <div class="welcome" id="welcome_show_page"> <%=content_tag :h2, :header do-%> <%=yield(:page_title)-%> <%- end -%> displays: a boy & his dog -- 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-/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.
On 7 Mar 2011, at 19:13, James Byrne <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote in post #986019: >> On 7 Mar 2011, at 17:42, James Byrne <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >>> In one of my views I have this code: >>> >>> <%=content_tag :h2, :header do-%> >>> <%=yield(:page_title).html_safe?-%> >>> <%=yield(:page_title).titleize-%> >>> <%- end -%> >>> >> >> What exactly does yield(:page_title) return before you titleize it? >> >> Fred > > <%-content_for :page_title, > "a boy & his dog" > -%>So the issue would seem to be that content_for is escaping the & (turning it into &), and then titleize, not knowing any better uppercases the & to &Amp. Character entities are case sensitive so this screws things up. Why not call titleize in the content_for block?> > <div class="welcome" id="welcome_show_page"> > > <%=content_tag :h2, :header do-%> > <%=yield(:page_title)-%> > <%- end -%> > > displays: > > a boy & his dog > > -- > 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-/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. >-- 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.
Frederick Cheung wrote in post #986030:> > So the issue would seem to be that content_for is escaping the & > (turning it into &), and then titleize, not knowing any better > uppercases the & to &Amp. Character entities are case sensitive so > this screws things up. Why not call titleize in the content_for block?Thank you Fred. Yes, that works. I did not think to do that because our practice is to apply styling methods at the moment of display. On this page I can change that without difficulty but on others, as the text is sometimes used in multiple places on a page, I may not be so fortunate as in this example. -- 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-/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.