2017-03-27 51 views

回答

0

你可以在ApplicationController中驗證這一點,如:

before_action :validate_user_role 

... 

def validate_user_role 
    flash[:alert] == "User don't have a Role" 
    redirect_to login_path if current_user.role.blank? 
end 
... 
3

一種方式有條件地允許用戶登錄是通過覆蓋設計的#active_for_authentication?方法:

class User < ActiveRecord::Base 
    def active_for_authentication? 
    super && role.present? 
    end 
end 

希望這有助於!

相關問題