Devise authenticate_user

前端 未结 1 1037
栀梦
栀梦 2021-02-06 11:07

help my in that question:

i have 2 models ( admin and user ) -> created with devise, and i have post_controller:

and the question arises:

if i have one m

1条回答
  •  [愿得一人]
    2021-02-06 11:37

    Try using two before filters - one for admin only actions, and another for admin or user actions.

    # ensure admin for other actions
    before_filter :check_admin_logged_in!, :except => [:show, :index]
    
    # ensure user or admin logged in for these actions (:only option is optional)
    before_filter :check_user_logged_in!, :only => [:show, :index]
    
    private
        def check_admin_logged_in! # admin must be logged in
            authenticate_admin!
        end
        def check_user_logged_in! # if admin is not logged in, user must be logged in
          if !admin_signed_in?
            authenticate_user!
          end   
        end
    

    0 讨论(0)
提交回复
热议问题