开发者

rails 3 partial content_for not showing up

I have a layout (application.html) that has this:

<!-- then anything added in the views -->
<%= yield :stylesheet %>

If I put this code 开发者_如何学Goin a 'root' template (ie the one called by an action directly) it renders on the page no problem:

<% content_for :stylesheet do %>
This is a test
<% end %>

But if I put the same thing in a partial it doesn't get rendered. The partial is rendered as such:

<%= render :partial => "detail" %>


Without seeing rest of the related code it is hard to know for sure but it could be an ordering problem.

From a high level, when the page renders, it first loads the view (before the layout) and any partials in the view with content_for should work correctly. However if this partial is being rendered in the layout instead of the view template, there is a chance the content_for will be called after the "yield :stylesheet" which would cause it to get ignored.


hmm, are you sure the partial is in the right directory.

I'm doing the exact same thing and it works no problem. in my version of home/_detail.html.erb (i.e., it's in the home directory) in my index.html.erb page i just put the same code as you have and it works no problem. You sure the spelling is write on the file name, and that you saved the file?

Are you sure you're spelling content for correctly or don't have misplaced tags? What do your tests say?

Also if it is in the head section, what if you added comment tags, instead of just plain text, maybe it doesn't like that?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜