开发者

Rails layout: 2 cols cache and content_for

Hy,

I have a layout that h开发者_C百科as 2 cols and in every view i have: content_for :main_col and content_for :side_col

in some parts of the site, the side_col is always the same and how do i do that being DRY? partial render? i dont think is so good.

then it comes to cache.. the content_for is not good to cache...

you have better ideias on how to implement this?thanks


your question is a bit vague, but from what i'm understanding, if you don't want to make a partial, then you could just put markup for side_col directly in the application layout instead of having the named yield. then make sure that any variables you need in that view are set in the ApplicationController. if there are views that don't require the side_col, then you can set an instance variable, say, @include_side_col = true in your application controller, then wrap the side_col in an if statement checking that variable. in your sub controllers, you could then set @include_side_col to false in a before_filter. That is one way to do it, but I must say that I would prefer the partial method as it is more of a rails convention, and it keeps you from cluttering your application layout

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜