Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new action to devise registrations_controller

my main devise route is:

devise_for :accounts,  :controllers => { :registrations => "users/accounts/registrations", :sessions => "accounts/devise/sessions" }, :class_name => 'Admin' 

Then I want a new url/action so i add the following BEFORE the devise_for line above:

match '/accounts/signedup/' => 'users/accounts/registrations#signedup':

then in the controller i have the signedup action, but when i go to myurl.com/accounts/signedup which currently just has:

def signedup
    Rails.logger.debug { "&& signed_up" }
end

Then I go to myurl.com/accounts/signedup I get:

AbstractController::ActionNotFound (AbstractController::ActionNotFound):

But if I remove the def signedup from the controller I instead get:

The action 'signedup' could not be found for Users::Accounts::RegistrationsController"

Any idea what's wrong?

like image 845
99miles Avatar asked Jan 27 '11 19:01

99miles


3 Answers

Your answer is correct, but the recent versions of devise have deprecated this behavior:

Passing a block to devise_for is deprecated. Please remove the block from devise_for (only the block, the call to devise_for must still exist) and call devise_scope :user do ... end with the block instead.

Judging by what you have posted, in your case you should probably use after_sign_in_path_for in your custom RegistrationsController.

Here is what I used in my project as an alternative:

  devise_scope :user do
    get 'session/on_signin', :to => 'sessions#memorize_session'
  end
like image 88
Georgi Atsev Avatar answered Nov 17 '22 00:11

Georgi Atsev


Solution was:

devise_for :accounts,  :controllers => { :registrations => "users/accounts/registrations", :sessions => "accounts/devise/sessions" }, :class_name => 'Admin' do
  get "accounts/signedup", :to => "users/accounts/registrations#signedup", :as => "signedup_registration"
end
like image 27
99miles Avatar answered Nov 17 '22 02:11

99miles


Using the following (make sure its not plural or you will get the error above).

devise_scope :user do
  get 'session/on_signin', :to => 'sessions#memorize_session'
end

Then you can modify the devise_for as usual if you need to pass custom controllers.

devise_for :users

like image 7
upisdown Avatar answered Nov 17 '22 00:11

upisdown