您可以检查
:sidebar
存在并呈现侧边栏(如果为真)。
轨道2.3.5将具有
content_for?
方法。同时,你可以使用我的
Helperful
宝石。
- if has_content?(:sidebar)
.grid_8
= render :partial => 'shared/search'
= yield
.grid_4
= yield(:sidebar)
- else
.grid_12
= render :partial => 'shared/search'
= yield
否则,可以假定:sidebar==false,然后没有sidebar。
def sidebar(enable = true, &block)
if enable
content_for :sidebar, &block
else
@fullpage = true
end
end
def fullpage?
!!@fullpage
end
- if fullpage?
.grid_12
= render :partial => 'shared/search'
= yield
- else
.grid_8
= render :partial => 'shared/search'
= yield
.grid_4
= yield(:sidebar)
更新:
如果您使用的是Rails 3.x,请检查
answer to a similar question
以获得正确的解决方案。上面的解决方案不适用于Rails 3。