#14 楼 @w7938940 render_list 应该是在 helper 里面定义的吧。我是先在 helper 里面定义了一个数组:
def global_nav_items
[{:id => 'index', :url => '/', :name => t(:page_index)}, {:id => 'screenshot', :url => '/screenshot/', :name => t(:page_screenshot)}, {:id => 'lines', :url => '/lines/', :name => t(:page_lines)}, {:id => 'fast', :url => '/fast/', :name => t(:page_fast)}]
end
然后在页面中:
- global_nav_items.each do |nav|
- active = nav[:id] == @page_id ? 'active' : ''
%li{:class => "#{active}"}
= link_to nav[:name], nav[:url]
每个页面有个 @page_id
,如果是当前页面,就给菜单项加个 class="active"