Module: Cookbook::Mixins::ActsAsUsedIn
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cookbook/mixins/acts_as_used_in.rb
Overview
ActsAsUseIn Mixin, for things like Tools, Supplies, or Ingredients
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Instance Method Summary collapse
Instance Method Details
#acts_as_used_in(*model_symbols) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cookbook/mixins/acts_as_used_in.rb', line 9 def acts_as_used_in(*model_symbols) extend ClassMethods include InstanceMethods self.use_of = model_symbols self.label_method = :name Cookbook::Use.add_use_of(table_name.to_sym) # Relationships has_many :uses, as: :use_of, class_name: 'Cookbook::Use', inverse_of: :use_of associate_uses_of if defined?(RailsAdmin) rails_admin do field :uses do visible false end self.use_of.each do |table_sym| # We don't want these associations to show table_uses_sym = "#{table_sym.to_s.singularize}_uses".to_sym field table_uses_sym do visible false end field table_sym do visible false end end end end end |