wael34218
wael34218

Reputation: 4930

Rails rendering content_for not working for partials

I am using a Rails 2.3.8 application. I have a layout file that contains
<%= yield :head %>

I called the following code in different parts of my application:
<% content_for :head do %>
<meta name="keywords" content="" />
<% end %>

I tried to add that code in a view file home it worked. I called it from patial _abc that is called from home it also worked as expected by adding the meta code in the head part. But when I added the code inside partial _def that is called from _abc which is called from home the meta tag did not show up!!!

I didnt usderstand what is going on... and how can bypass this problem

UPDATE: The case that did not work was:

home.html.erb:
<%= render :partial=>"_abc"%>

_abc.html.erb:
<%= render :partial=>"_def"%>

_def.html.erb:
<% content_for :head do %>
<meta name="keywords" content="" />
<% end %>

Thanks a lot

Upvotes: 2

Views: 2732

Answers (1)

Sk&#228;ggiga Mannen
Sk&#228;ggiga Mannen

Reputation: 1043

This is an old question, but I got here with a similar issue. Figured I'd post my issue/solution in case someone else lands here.

Which file is <%= yield :head %> in? I had this issue and it turned out my yield was in the "/layouts/application.html.erb" file... But the view being called was using a different layout file i.e. "/layouts/listings.html.erb". once I moved the yield into the correct file, everything worked fine, and I had pretty much the same setup you described.

Upvotes: 2

Related Questions