代码之家  ›  专栏  ›  技术社区  ›  Jason

在使用device时,如何在注册后重定向用户?

  •  22
  • Jason  · 技术社区  · 15 年前

    我正在使用Rails 2.3并设计处理用户注册/身份验证。

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

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

    3 回复  |  直到 9 年前
        1
  •  28
  •   Carlos A. Cabrera    11 年前

    添加到您的 应用控制器

      # 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

    我希望这有帮助=)

        2
  •  53
  •   user229044    13 年前

    答案列为“ 对的 “答案具体指在登录后……如果要在注册后重定向用户,则需要重写以下内容:

    def after_sign_up_path_for(resource)
      "http://www.google.com" # <- Path you want to redirect the user to after signup
    end
    

    有关详细信息,请访问 the wiki .

        3
  •  18
  •   declan    13 年前

    如果您使用的是DEVICE的确认(即用户注册后不会立即激活),则需要覆盖 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
    

    一定要告诉迪奇使用你的注册控制器。

    # config/routes.rb
    devise_for :users, :controllers => {:registrations => 'registrations'}