[英]Ruby on Rails: current_page? problem when using actions
I'm now implementing navigation tabs for my Rails application. 我现在正在为Rails应用程序实现导航选项卡。 I would like to generate different CSS and html for current tab (add id="current" and do not link the title) - basic stuff. 我想为当前选项卡生成不同的CSS和html(添加id =“ current”并且不链接标题)-基本内容。
I found the function: current_page? 我找到了函数: current_page? but unfortunately it doesn't work in a way i would expect: 但不幸的是,它不能以我期望的方式工作:
When I call: current_page?(:controller => "bank_account") it returns true for /bank_account but not for /bank_account/soem_action 当我调用:current_page?(:controller =>“ bank_account”)时,它对/ bank_account返回true,但对/ bank_account / soem_action不返回true
Is there a way to force current_page? 有办法强制current_page吗? to return true in this case? 在这种情况下返回true? So when I don't specify the action it should return true for all the actions of the given controller. 因此,当我不指定操作时,对于给定控制器的所有操作,它应该返回true。
Look at this answered question: 看这个回答的问题:
link_to_unless_current fails when processing forms with error messages in it with restfull routes 当使用restfull路由处理带有错误消息的表单时,link_to_unless_current失败
You could use 你可以用
controller.controller_name
to retrieve the controllers name in a view. 在视图中检索控制器名称。
See this gist . 看到这个要点 。 Usage instructions in article A Better Way to Add a 'selected' Class to Links in Rails . 《在Rails中向链接添加“选定的”类的更好方法》中的用法说明。 Linked to from question Best way to add “current” class to nav in Rails 3 . 从问题链接到在Rails 3中将“当前”类添加到nav的最佳方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.