Jas*_*son 22 ruby ruby-on-rails devise
我正在使用Rails 2.3和Devise来处理用户注册/身份验证.
我需要在用户注册帐户后立即将用户重定向到外部第三方网站.一直在寻找代码和在线,但看不到如何做到这一点.
如何更改设计流程以重定向用户?
Bre*_*din 53
列为" 正确 "答案的答案具体是指在sign_in之后......如果您想在sign_up之后重定向用户,则需要覆盖以下内容:
def after_sign_up_path_for(resource)
"http://www.google.com" # <- Path you want to redirect the user to after signup
end
Run Code Online (Sandbox Code Playgroud)
完整的详细信息可以在维基上找到.
Car*_*era 28
添加到应用程序控制器
# Devise: Where to redirect users once they have logged in
def after_sign_up_path_for(resource)
"http://www.google.com" # <- Path you want to redirect the user to.
end
Run Code Online (Sandbox Code Playgroud)
以下是您可以使用的Devise助手列表http://rdoc.info/github/plataformatec/devise/master/Devise/Controllers/Helpers
我希望有帮助=)
dec*_*lan 18
如果您正在使用Devise的确认(意味着用户在注册后未立即激活),则需要覆盖该after_inactive_sign_up_path_for方法.
# controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def after_inactive_sign_up_path_for(resource)
"http://somewhere.com"
end
end
Run Code Online (Sandbox Code Playgroud)
确保告诉devise使用您的RegistrationsController.
# config/routes.rb
devise_for :users, :controllers => {:registrations => 'registrations'}
Run Code Online (Sandbox Code Playgroud)