24

我正在使用 Rails 2.3 和 Devise 来处理用户注册/身份验证。

我需要在用户注册帐户后立即将用户重定向到外部第三方网站。一直在查看代码和在线,但看不到如何执行此操作。

如何更改设计流程以重定向用户?

4

3 回答 3

56

列为“正确”答案的答案专门指在 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

完整的细节可以在wiki上找到。

于 2011-07-22T05:43:31.407 回答
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

这是您可以使用的设计助手列表http://rdoc.info/github/plataformatec/devise/master/Devise/Controllers/Helpers

我希望这会有所帮助=)

于 2010-09-03T14:07:52.183 回答
19

如果您使用的是 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

确保告诉设计使用您的 RegistrationsController。

# config/routes.rb
devise_for :users, :controllers => {:registrations => 'registrations'}
于 2012-04-23T19:48:58.233 回答