簡體   English   中英

如何僅在Ruby on Rails 3中將current_user限制為已確認的用戶?

[英]How to restrict current_user to confirmed users only in Ruby on Rails 3?

我還是Rails的新手,我想調整以下(相當標准的)代碼,以便任何current_user都需要將其confirmed數據庫字段設置為true 換句話說,如果userconfirmed數據庫字段為false他不應該成為current_user

module SessionsHelper

  def current_user=(user)
    @current_user = user
  end  

  def current_user
    @current_user ||= User.find_by_token(cookies[:token]) if cookies[:token]
  end

  def current_user?(user)
    user == current_user
  end

end

怎么能實現這一目標?

謝謝你的幫助。

def current_user
  user = User.find_by_token(cookies[:token]) if @current_user.nil? && cookies[:token]
  @current_user ||= user if user && user.confirmed 
end

暫無
暫無

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

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