On Jan 23, 11:50 am, “[email protected]”
[email protected] wrote:
but after logging in, I’m redirected to “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
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
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