作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在实现 current_page?
为了测试当前 Controller 和 Action 是否等于某个值,但是在该 Controller / Action 组合上它不会返回 true。
- if current_page?(:controller => 'pages', :action => 'main')
# doesn't return true when on that controller/action combination
- if controller.controller_name == 'pages' && controller.action_name == 'main'
# this works just fine
rake routes
:
pages_main GET /pages/main(.:format) {:controller=>"pages", :action=>"main"}
root /(.:format) {:controller=>"pages", :action=>"main"}
Started GET "/" for 127.0.0.1 at 2011-03-03 16:54:40 -0500
Processing by PagesController#main as HTML
Rendered pages/main.html.haml within layouts/application (203.8ms)
最佳答案
current_page?(root_path)
工作正常。
但我不能让它与 :controller
一起工作和 :action
似乎助手需要一个字符串,所以:
current_page?(url_for(:controller => 'pages', :action => 'main'))
关于ruby-on-rails - Rails current_page?与 controller.controller_name 对比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5186613/
我正在实现 current_page?为了测试当前 Controller 和 Action 是否等于某个值,但是在该 Controller / Action 组合上它不会返回 true。 - if c
我是一名优秀的程序员,十分优秀!