我正在尝试构建一个块助手,但我似乎无法找到访问 current_page 的方法?从班内。
我的帮助文件如下所示:
class NavList
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
def header(title)
content_tag :li, title, class: 'nav-header'
end
def link(title, path, opts={})
content_tag :li, link_to(title, path), class: opts[:class]
end
end
def nav_list(&block)
new_block = Proc.new do
helper = NavList.new
block.call(helper)
end
content_tag :ul, capture(&new_block), class: 'nav nav-list'
end
我可以通过
<%= nav_list do |nl| %>
<%= nl.header 'Location' %>
<%= nl.link 'Basic Information', url_for(@department), class: current_page?(@departments) ? 'active' : '' %>
<%= nl.link 'Employees', department_users_path(@department) %>
<% end %>
但我想做的是不必经常参加那个活跃的课程。所以我想做这样的事情
def link(title, path, opts={})
css_class = 'inactive'
css_class = 'active' if current_page?(path)
content_tag :li, link_to(title, path), class: opts[:class]
end
但我找不到使用 current_page 的方法?从 NavList 类中。它与未找到的请求方法有关