Set a field in all models

0

I'm trying to create an app that works with multiple companies and I always need to save the company_id field whenever I create and / or update any model , what is the best way to do this? to do this?

I thought of a before_action around models , but I get one

undefined method 'before_action' for #<Class:0x007fcfd9438d38>

One of the models is this:

class Config < ApplicationRecord
  before_action :set_current_user

  def set_current_user
    User.current = current_user
  end

  belongs_to :company

validates :company_id, uniqueness: true

  dragonfly_accessor :logo

  before_save :set_company

  private
    def set_company
      self.company_id = current_user.company_id
    end
end
    
asked by anonymous 17.02.2017 / 18:45

0 answers