简体   繁体   English

Ruby on Rails:current_page? 使用动作时出现问题

[英]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。

You could use 你可以用

controller.controller_name 

to retrieve the controllers name in a view. 在视图中检索控制器名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM