Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Has anybody experienced routes mysteriously becoming undetectable when using current_page? in Rails 3? Even with a fully generated scaffold complete with routes, a view, and a controller, I am getting a "No route matches" error.

Here's the code:

if current_page?(:controller => 'users', :action => "show")

If I add a "match" command to routes.rb, it works fine, but why would I need to do that if the resources have already been created? What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...