Trouble with titleize

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.

On 7 Mar 2011, at 17:42, James B. [email protected] 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

Frederick C. wrote in post #986019:

On 7 Mar 2011, at 17:42, James B. [email protected] 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”
-%>

<%=content_tag :h2, :header do-%>
<%=yield(:page_title)-%>
<%- end -%>

displays:

a boy & his dog

On 7 Mar 2011, at 19:13, James B. [email protected] wrote:

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 &amp), and then titleize, not knowing any better
uppercases the &amp to &Amp. Character entities are case sensitive so
this screws things up. Why not call titleize in the content_for block?

Frederick C. wrote in post #986030:

So the issue would seem to be that content_for is escaping the &
(turning it into &amp), and then titleize, not knowing any better
uppercases the &amp 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.