Rails 2.3.7 and content_for problem

I want to offer control over my app’s navigation using multiple
yields, which worked fine on my home rails 3 installation, but at
work, I’m stuck with an app that uses 2.7, and the same approach isn’t
working.

Basically, I have 3 yields: <% yield :navigation%> <% yield :sidebar
%> and regular ol’ yield.

The regular one works fine, of course. However, the other two result
in certain tags being escaped:

    ,
  • , , etc. The result is
    that the tags appear as text in the display, and aren’t interpreted by
    the browser. I’ve tried the few suggestions I’ve found on the internet
    (prefix the content_for with raw, etc), however, nothing has changed
    the outcome. I should say that link_to in the content_for block is
    properly handled and is not escaped, which is pretty interesting to
    me.

    I’ve reproduced the problem to a newly generated app with 1 scaffold
    based class, with only minor alterations (adding the application.erb
    and modifications to the index.html.erb file. Note that the navigation
    content_for shows the list markup as text, but obeys the output of
    link_to as markup.

    application.erb:

    <%= raw yield :navigation %>
     <%= yield %>
    

    index.html.erb:
    <% content_for :navigation do %>

    • <%= link_to 'New page', new_page_path %>
    <% end %>

    Listing pages

    <% @pages.each do |page| %>

    <% end %>
    Title Body
    <%=h page.title %> <%=h page.body %> <%= link_to 'Show', page %> <%= link_to 'Edit', edit_page_path(page) %> <%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs