Tag: 当前页面

Rails current_page? 与controller.controller_name相对

我正在实施current_page? 为了测试当前控制器和动作是否等于某个值,但是在该控制器/动作组合上它不会返回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 我的语法错了还是在这里发生了其他事情? 有没有更好的方法来做到这一点,比如设置BOOL或者这是正确的方法吗? 最终目标是仅在主着陆页上显示某个标题,同时在所有其他页面上显示不同的标题。 编辑 : rake routes相关输出: pages_main GET /pages/main(.:format) {:controller=>”pages”, :action=>”main”} root /(.:format) {:controller=>”pages”, :action=>”main”} 此外,这是渲染时的服务器输出: Started GET “/” for […]