The same current_user on multiple models in devise

后端 未结 4 1241
囚心锁ツ
囚心锁ツ 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:46

    I think this way you allow a user to be signed in as a User and a Voluteer in the same session.

    Once you have a way to deal with that could you not just have

    # in application_controller.rb
    alias_method :devise_current_user, :current_user
    def current_user
      devise_current_user || current_volunteer
    end
    

    in your application_controller.rb

提交回复
热议问题