簡體   English   中英

使用Devise注冊后確定重定向路徑

[英]Determine redirect paths after sign up with Devise

我可以使用兩種類型的用戶注冊我的應用程序,即“女孩”和“男孩”。 如果有女孩注冊,我想重定向到“ / girls”,如果有男孩注冊,我想重定向到“ / boys”。

是否可以使用Devise進行自定義重定向?

我找到的最接近的文檔在這里: https : //github.com/plataformatec/devise/wiki/How-To :-redirect-to-a-specific-page-on-successful-sign- in 問題是我無法進行任何檢查來切換重定向路由。

我考慮過的選項:

  1. 當用戶單擊“注冊”時,傳遞一個附加的URL參數。 ?is_girl=1
  2. 他們單擊“ sign-up ,在確定重定向路線時,我可以查看用戶模型,看看他們是女孩還是男孩。 然后相應地重定向。

我假設在注冊過程中,您詢問他們是男孩還是女孩,並將其保存在數據庫中。

所以您只需要像Devise文檔中的示例所示

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    if resource.sex == 'boy'
      '/boy' # or you could create a route in routes.rb and do boy_path
    else
      '/girl' # with routes setup: girl_path
  end
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM