开发者

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:

开发者_StackOverflow社区
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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜