“No routes matches” when using current_page in Rails 3

試著忘記壹切 提交于 2019-11-29 13:18:47

You're missing the id parameter from this helper:

current_page?(:controller => "users", :action => "show", :id => "1")

It expects you to pass a full route through. If you don't want this and only want to match on the controller and action then I would recommend coding your own.

If you just want to test the current controller, you can do the following:

if params[:controller] == 'users'

Similarly, if you're using a namespaced controller, you can just use a slash to separate the namespace(s) from the controller name, e.g.:

if params[:controller] == 'advertising/users'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!