When I access /users/registration/sign_up in my app via the browser (GET) a page renders. When I do the same thing via POST (either by submitting a form w/ the target /users/registration/sign_up or with ajax) my app returns the following error:
Unknown action The action 'registration' could not be found for UsersController
I am using devise for authentication and creating a devise route for my User model using:
devise_for :users
This path should route to the devise/registrations_controller where i expect it to execute the new method (it currently does for a GET request). Maybe rails, understanding the request is a POST request automatically directs it to the create method but I don't think this is the issue because I start the debugger first thing in the create method and the debugger is not starting in my terminal befo开发者_如何转开发re I receive this error.
Can anyone with experience with devise decipher what's going on? I'm happy to provide more info if necessary. Thanks.
Devise adds routes to your Rails app, which you can see by running rake routes
from a terminal:
new_user_session GET /users/sign_in(.:format)
user_session POST /users/sign_in(.:format)
destroy_user_session GET /users/sign_out(.:format)
user_password POST /users/password(.:format)
new_user_password GET /users/password/new(.:format)
edit_user_password GET /users/password/edit(.:format)
PUT /users/password(.:format)
user_registration POST /users(.:format)
new_user_registration GET /users/sign_up(.:format)
edit_user_registration GET /users/edit(.:format)
PUT /users(.:format)
DELETE /users(.:format)
root /(.:format)
And as you discovered, there is a GET /users/sign_up
but no POST /users/sign_up
. When creating Devise expects POST /users
, for which you can use the helper method user_registration_path
. This gets handled by Devise::RegistrationsController#create
.
精彩评论