![](/img/trans.png)
[英]how can I display all users except current user and current_user's friends in ruby on rails
[英]How to restrict current_user to confirmed users only in Ruby on Rails 3?
我還是Rails的新手,我想調整以下(相當標准的)代碼,以便任何current_user
都需要將其confirmed
數據庫字段設置為true
。 換句話說,如果user
的confirmed
數據庫字段為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.