views:

56

answers:

4

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?

A: 

Tried

redirect_to :url => {:action => 'login', :controller => 'user'}

Or you might have to remove the routing or write your own. The routing maps POST to create, PUT to update etc.

Terw
A: 

You need to add the login action in your routes.rb. Refer to this excellent guide.

JRL
+1  A: 

The hack-y answer is to change the following line in your routes.rb

map.resources :user

to

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/new to login. You can alias it to /login by the following line in routes.rb

map.login 'login', :controller=>"sessions", :action=>"new"

Ron Gejman
+1 but I don't think it's such a big deal to break the restful paradigm. The universe contains more than 4 verbs. :-)
MattMcKnight
My answer was functionally the same as this, I think. Thanks for your help.
kubi
A: 

What I ended up doing was creating a new login_controller to handle logins.

Here's the relavent bit from my routes.rb file:

map.login '/login', :controller => 'login', :action => 'login'

Thanks for your help...

kubi