In a Rails controller I’m calling this:
redirect_to :controller => "user", :action => "login"
My user_controller.rb defines the following method:
class UserController < ApplicationController
def login
###
end
When I call my redirect_to method I get this error in my browser: No action responded to show. Checking the server logs I see this line:
Processing UserController#show (for 127.0.0.1 at 2009-12-19 12:11:53) [GET]
Parameters: {"action"=>"show", "id"=>"login", "controller"=>"user"}
Finally, I’ve got this line in my routes.rb
map.resources :user
Any idea what I’m doing wrong?
The hack-y answer is to change the following line in your routes.rb
map.resources :userto
map.resources :user, :collection => { :login => :get }But that’s bad for a variety of reasons — mainly because it breaks the RESTful paradigm. Instead, you should use a SessionController and use
sessions/newto login. You can alias it to/loginby the following line in routes.rbmap.login 'login', :controller=>"sessions", :action=>"new"