问题
I am building a Rails application (using ActiveAdmin and Devise) and I am trying to override the after_sign_up_path_for to change the redirection after signing up.
I followed this tutorial from devise but my RegistrationsController is never called. I guess it might work a little bit differently with ActiveAdmin.
I also tried other solution I found on stack overflow without any luck.
Here is my routes:
Rails.application.routes.draw do
devise_config = ActiveAdmin::Devise.config
devise_config[:controllers][:omniauth_callbacks] = 'users/omniauth_callbacks'
devise_config[:controllers][:registrations] = 'registrations'
devise_for :users, devise_config
ActiveAdmin.routes(self)
# other routes
end
And my RegistrationsController: (which is never called)
class RegistrationsController < ActiveAdmin::Devise::RegistrationsController
protected
def sign_up(_resource_name, _resource)
true
end
def after_sign_up_path_for(_resource)
root_url
end
end
Thanks for your help !
My project:
- Rails 4.2.6
- ActiveAdmin 1.0.0.pre2
- Devise 3.5.9
回答1:
ActiveAdmin don't use your RegistrationsController and can't use them. You can define that method on your ApplicationController or you can do it this way:
# conig/initializer/active_admin.rb
ActiveAdmin::Devise::RegistrationsController.class_eval do
def after_sign_up_path_for(_resource)
root_url
end
end
来源:https://stackoverflow.com/questions/37147452/how-can-i-override-after-sign-up-path-for-in-activeadmin