本文介绍了如何覆盖“after_sign_up_path_for”在ActiveAdmin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Rails应用程序(使用 ActiveAdmin Devise ),我试图覆盖 after_sign_up_path_for 以更改签名后的重定向

我遵循这个,但我的 RegistrationsController 从未被调用。我猜这可能与ActiveAdmin有所不同。



我也尝试过其他解决方案,我发现堆栈溢出没有任何运气。



以下是我的路线

  Rails.application.routes.draw do 
devise_config = ActiveAdmin :: Devise.config
devise_config [:controllers] [:omniauth_callbacks] ='users / omniauth_callbacks'
devise_config [:controllers] [ :注册] ='注册'
devise_for:users,devise_config

ActiveAdmin.routes(self)
#其他路线
end

我的注册控制器:(从不调用)

  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

感谢您的帮助! / p>

我的项目




  • Rails 4.2.6

  • ActiveAdmin 1.0.0.pre2

  • Devise 3.5.9


解决方案

ActiveAdmin不使用您的注册控制器,不能使用它们。您可以在ApplicationController上定义该方法,或者您可以这样做:

 #conig / initializer / active_admin.rb 
ActiveAdmin :: Devise :: RegistrationsController.class_eval do
def after_sign_up_path_for(_resource)
root_url
end
end


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

解决方案

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

这篇关于如何覆盖“after_sign_up_path_for”在ActiveAdmin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:30