2

我试图在注册后设计重定向到自定义页面。它不工作。我有以下的自定义登记控制器:after_sign_up_path_for not working - devise

class RegistrationsController < Devise::RegistrationsController 
    protected 

    puts 'Registrations controller is happening" 

    def after_sign_up_path_for(resource) 
    puts 'after_sign_up_path_for is working' 
    "http://www.google.com" 
    end 

    def after_inactive_sign_up_path_for(resource) 
    puts 'after_inactive_sign_up_path_for is working' 
    "http://www.google.com" 
    end 
end 

这里是我的自定义路线:

devise_for :users, :controllers => { :registrations => :registrations } 

那么,什么是有趣的是,登记控制器工作时,因为第一个看跌期权声明中显示出来服务器日志。但是,第二个和第三个put语句(在after_sign_up_path_for和after_inactive_sign_up_path_for内)没有出现。

注册后如何获得重定向?

+0

它不是重复的。我看到了这个问题,答案对我来说不起作用。 – Philip7899

+0

你检查了其他答案吗? – Ashitaka

+1

是的,我已经查看了所有堆栈溢出页面和我能找到的其他资源。 – Philip7899

回答

0

我建议你将这些助手移动到ApplicationController(见docs)并将它们放在公共命名空间中。

+0

谢谢,但我不认为这将是有效的,因为它不应该通过每个控制器操作之后经过该方法,就像它在应用程序控制器中一样。这只是回到某些页面。只有在用户尝试注册时才能看到此方法。至少这是我从这些焦点获得的:https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration ) – Philip7899

+0

我试过了,但它仍然无法工作。 – Philip7899

+0

我在路线中看到的另一个区别,你尝试':registrations =>'registrations''?字符串值我的意思是? –