How can I override “after_sign_up_path_for” in ActiveAdmin?

点点圈 提交于 2019-12-13 19:17:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!