开发者

Want to define a section in my application_layout, but override it in a particular case, possible?

Say my application layout is like has:

<div id=container>

<div id=content>
<%= yield %>
</div>
</div id=sidebar>
   <div id=top></div>
   <div id=bottom></div>
</div>
  1. Now on the about page, I want to hide the s开发者_如何学Goidebar section, how could I do this?
  2. on the contact page, I want to override the contents of the sidebar.bottom part? is that possible?


In your application_controller.rb

before_filter :enable_sidebar
def enable_sidebar
  @show_sidebar = true
end

In your about action:

def about
  @show_sidebar = false
end

In your layout

<% if @show_sidebar %>
  <div id="sidebar">
  ...
  </div>
<% end %>

Use a similar approach for your contact page, or use a symbol value rather than a boolean to select different sidebar variations. The idea is the same: set a default, and then set some controller instance variables to alter depending on your needs on a per-action basis.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜