# Restful\_authentication: getting error when trying to login

**URL:** <https://www.ruby-forum.com/t/restful-authentication-getting-error-when-trying-to-login/126948>\
**Category:** Rails\
**Created:** [January 23, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/restful-authentication-getting-error-when-trying-to-login/126948 "2008-01-23T17:51:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 23, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/restful-authentication-getting-error-when-trying-to-login/126948/1 "2008-01-23T17:51:42Z")

</div>

Hi,

After downloading the restful\_authentication plugin, I have the  
following in my config/routes.rb file:

map.signup ‘/signup’, :controller =\> ‘users’, :action =\> ‘new’  
map.login ‘/login’, :controller =\> ‘session’, :action =\> ‘new’  
map.logout ‘/logout’, :controller =\> ‘session’, :action =\> ‘destroy’

and here is my login form:

\<%= form\_tag(‘/login’, :method =\> :post) %\>

| Login: | \<%= text\_field\_tag("login", '') %\> |
| Password: | \<%= password\_field\_tag("password", '') %\> |
| \<%= submit\_tag("Login") %\> |

\<%= end\_form\_tag %\>

but after logging in, I’m redirected to “[mydomain.com/session](http://mydomain.com/session)” and I  
get this error:

Unknown action  
No action responded to show

Oh, and this is the session controller I have …

class SessionController \< ApplicationController

# Be sure to include AuthenticationSystem in Application Controller

instead  
include AuthenticatedSystem

# render new.rhtml

def new  
redirect\_to :action =\> ‘create’  
end

def create  
self.current\_user = User.authenticate(params[:login],  
params[:password])  
if logged\_in?  
if params[:remember\_me] == “1”  
self.current\_user.remember\_me  
cookies[:auth\_token] = { :value =\>  
self.current\_user.remember\_token , :expires =\>  
self.current\_user.remember\_token\_expires\_at }  
end  
redirect\_back\_or\_default(‘/’)  
flash[:notice] = “Logged in successfully”  
else  
render :controller =\> ‘register’, :action =\> ‘start’  
end  
end

Why am I getting this error? - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 27, 2008, 12:42am UTC](https://www.ruby-forum.com/t/restful-authentication-getting-error-when-trying-to-login/126948/2 "2008-01-27T00:42:05Z")

</div>

On Jan 23, 11:50 am, “removed\_email\_address@domain.invalid”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but after logging in, I’m redirected to “[mydomain.com/session](http://mydomain.com/session)” and I  
> get this error:
> 
> Unknown action  
> No action responded to show

I encountered the same error messages when I used the  
restful\_authentication plugin and tried to add new actions to my users  
controller. When I looked at the server log files, I saw this error  
message:

Parameters: {“action”=\>“show”, “id”=\>“newaction”,  
“controller”=\>“users”}  
ActionController::UnknownAction (No action responded to show):

I received these error messages because, per the installation  
instructions for restful\_authentication, I had added this line of code  
to my routes.rb file:

map.resources :users, :member =\> { :suspend =\> :put, :unsuspend  
=\> :put, :purge =\> :delete }

The call to ActionController::resources here defines the users class  
as a RESTful resource:

[http://api.rubyonrails.org/classes/ActionController/Resources.html](http://api.rubyonrails.org/classes/ActionController/Resources.html)

which means (among other things) that by default the class only  
supports six actions - new, create, show, edit, update and destroy.  
Each of these actions uses one of the four basic HTTP verbs - GET,  
POST, PUT and DELETE.

If we go back to this line from routes.rb:

map.resources :users, :member =\> { :suspend =\> :put, :unsuspend  
=\> :put, :purge =\> :delete }

it appears that our controller should support not only the standard  
six actions but also a ‘suspend’, ‘unsuspend’ and ‘purge’ action. If  
you type ‘rake routes’, you should see routes for these actions. (If  
you don’t, make certain that there is only one “map.resources :users”  
line in routes.rb) The routes that rake prints for these non-RESTful  
actions should look something like this:

suspend\_user PUT /users/:id/suspend  
{:controller=\>“users”, :action=\>“suspend”}  
formatted\_suspend\_user PUT /users/:id/suspend.:format  
{:controller=\>“users”, :action=\>“suspend”}

Note the :id parameter - these actions all operate on an existing  
object (which, of course, has an ID). But this won’t work for the  
‘create’ action you said you wanted to add to your controller, since  
you want to create a new object, not modify an existing one. In this  
case, you should use :collection instead of :member, like so:

map.resources :users,  
:member =\> { :suspend =\> :put, :unsuspend =\> :put, :purge  
=\> :delete },  
:collection =\> { :create =\> :get}

The API documentation for ActionController::resources has more  
information. Another useful source of information about RESTful  
interfaces is the “Advanced Rails Recipes” Beta Book:

[Pragmatic Bookshelf: By Developers, For Developers](http://www.pragprog.com/titles/fr_arr)

The book has a chapter entitled “Adding Your Own REST Actions (Or  
Not)” that provides more detail about how to add custom actions to a  
RESTful resource that was created by ActionController::Resources.

If you are just interested in renaming the ‘new’ action to ‘create’  
instead of making up new types of actions, then you could try playing  
around with these modifications to routes.rb:

map.login ‘/login’, :controller =\> ‘sessions’, :action =\> ‘new’  
map.logout ‘/logout’, :controller =\> ‘sessions’, :action =\>  
‘destroy’

These two examples are printed out when you run the ‘authenticated’  
generator. If you didn’t save the output of the generator when you  
first ran it, just look in this file:

vendor/plugins/restful\_authentication/generators/authenticated/  
authenticated\_generator.rb

I suspect you don’t want to completely get rid of the ‘new’ action,  
since this will break some of the RESTful behavior.

Hope this helps,

craig
