The same current_user on multiple models in devise

后端 未结 4 1254
囚心锁ツ
囚心锁ツ 2020-12-20 09:10

Problem

I have a User model, and the Volunteer model that inherits from the User model:

class User < ActiveRecord::Base
end

class Volunteer <         


        
4条回答
  •  心在旅途
    2020-12-20 09:41

    I faced similar problem and solved it like this. But is this solution is specific for cancan gem.

    application_controlller.rb

    def actual_user
      @actual_user ||= current_user.present? ? current_user : current_volunteer
    end
    
    def current_ability
      @current_ability ||= Ability.new(actual_user)
    end
    

提交回复
热议问题