开发者

Rails rendering content_for not working for partials

开发者 https://www.devze.com 2023-03-14 03:53 出处:网络
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:

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 cas开发者_Go百科e 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消