我在导航菜单中有一些静态页面。我想在当前显示的项目中添加更多元素。
视图布局导航/adminzor.html.erb
<ul class='main-nav'>
<%= nav_link 'Dashboard', adminzor_path %>
</ul>
在application_helper.rb 上
def nav_link(link_text, link_path)
class_name = current_page?(link_path) ? 'active' : ''
content_tag(:li, :class => class_name) do
link_to link_text, link_path
end
end
并输出
<ul class='main-nav'>
<li class="active">
<a href="/adminzor">Dashboard</a>
</li>
</ul>
因为我将nav_link助手与TwitterBootstrap的nav组件一起使用,后者更喜欢将链接封装在li标签中,并将"active"类应用于外部li。我在视图中添加了一些元素,例如
<%= nav_link adminzor_path, :class => "light" do %>
<div class="ico"><i class="icon-home icon-white"></i></div>
Dashboard
<% end %>
和辅助
def nav_link(link_text, link_path)
class_name = current_page?(link_path) ? 'active' : ''
content_tag(:li, :class => class_name) do
link_to link_path do
link_text
end
end
end
但是错误
ArgumentError in Adminzor/dashboards#index
Showing c:/Sites/zionrails/app/views/layouts/adminzor.html.erb where line #44 raised:
wrong number of arguments (3 for 2)
我想要像这样的输出
<ul class='main-nav'>
<li class="active">
<a href="/adminzor" class="light">
<div class="ico">
<i class="icon-home icon-white"></i>
</div>Dashboard
</a>
</li>
</ul>
还有其他解决方案吗?感谢
def menu_link(link_text, icon_type, link_path)
class_name = current_page?(link_path) ? 'active' : ''
content_tag(:li, :class => class_name) do
link_to link_path do
content_tag(:i, '', :class => icon_type) + link_text
end
end
end
电话:
<%= menu_link('My lists', 'icon-list', user_lists_path(@user)) %>
已解决
application_helper.rb
def is_active?(link_path)
if current_page?(link_path)
"active"
else
""
end
end
以及布局/adminzor.html.erb,如
<li class="<%= is_active?(adminzor_path) %>">
<%= link_to adminzor_path, :class => 'light' do %>
<div class="ico"><i class="icon-home icon-white"></i></div>
Dashboard
<% end %>
</li>