我正在使用此代码通过 Twitter Bootstrap 突出显示当前事件的菜单选项卡:
def nav_link_to(link_text, link_path, options = nil)
class_name = current_page?(link_path) ? 'active' : ''
content_tag(:li, :class => class_name) do
link_to link_text, link_path, options
end
end
这当然会使链接处于事件状态,仅当给定链接是当前页面时。
如何更改此功能,以便它为当前 Controller 下方的任何链接返回“事件”?
换句话说,对于 Posts Controller 的所有操作,链接将处于事件状态?
最佳答案
您可以使用 controller_name
获取当前 Controller 的名称。
关于ruby-on-rails - 如何在 Rails 中获取 URL 的当前 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11275214/