Reputation: 4484
I'm trying to overwrite Devise
registration controller and here is my setup:
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!, :only => :token
def new
super
end
def create
@request.env["devise.mapping"] = Devise.mappings[:user]
@user = User.new(params[:user])
if @user.save
render 'create.js', :success => true
else
render 'create.js', :success => false
end
end
end
routes.rb
(...)
devise_for :users, :controllers => {:sessions => 'sessions', :registrations => 'registrations'}
match 'registrations/create' => 'registrations#create' , :as => :user_register
# not matter if i'll put `match 'registrations/create'` line above or under the `devise_for` line
(...)
And it all (when i'll point my browser to registrations/create
) gives me an error:
Unknown action
Could not find devise mapping for path "/registrations/create". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do match "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]
I've found some threads describing similar issue but they were not helpfull at all. Thank you for any advice!
Upvotes: 3
Views: 2506
Reputation: 3153
As the error message clearly states, you need to wrap your Devise routes in a block like so:
devise_scope :user do
match 'registrations/create' => 'registrations#create', :as => :user_register
end
Devise does not accept routes outside of that block.
Upvotes: 5