ruby-on-railsrubyruby-on-rails-3current-page

"No routes matches" when using current_page in Rails 3


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?


Solution

  • 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.