ben
ben

Reputation: 29807

How do I fix this routing error in Ruby on Rails?

I've put this line in my routes.db file:

map.mything '/mything', :controller => 'mything', :action => 'list'

But I get this error when I go to http://localhost:3000/mything, I get this error:

Unknown action
No action responded to index. Actions: list

Why is it trying to use index instead of list? I thought that by setting

:action => 'list'

it would use the list action? Thanks for reading.

Upvotes: 1

Views: 784

Answers (3)

Jim Schubert
Jim Schubert

Reputation: 20367

You have to put named routes above the default routes.

I put named routes like these at the top of routes.rb so they always get evaluated first.

ActionController::Routing::Routes.draw do |map| 
  map.about 'about', :controller => 'home', :action => 'about'
  map.contact 'contact', :controller => 'home', :action => 'contact'

  # MORE CONFIG

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

Upvotes: 1

Jamie Wong
Jamie Wong

Reputation: 18350

Agreeing with Jim Schubert, put the named routes above the default routes.

Another likely problem is that you have something like:

map.resources :mything

which is setting an index action on the controller as a result of you scaffolding a model

Upvotes: 1

adriandz
adriandz

Reputation: 999

Sorry for asking a potentially obvious question, but have you tried restarting the app? Certain routes will not register until you restart the application (RESTful resources never need an application restart, but others often do).

Upvotes: 0

Related Questions