Module: Assetable::Base::ClassMethods
- Defined in:
- lib/assetable/active_record/base.rb
Instance Method Summary collapse
Instance Method Details
#assetable(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/assetable/active_record/base.rb', line 9 def assetable *args if args.present? args.each do |arg| has_one :"#{arg}_association", -> { where(name: arg) }, class_name: "AssetAttachment", as: :assetable has_one arg, through: :"#{arg}_association", source: :asset accepts_nested_attributes_for :"#{arg}_association", allow_destroy: true end end end |
#galleryable(*args) ⇒ Object
Galleries
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/assetable/active_record/base.rb', line 20 def galleryable *args # By default, let's include a gallery. unless args.include? :gallery has_one :gallery, as: :galleryable, dependent: :destroy accepts_nested_attributes_for :gallery end if args.present? args.each do |arg| has_one arg, -> { where(name: arg) }, class_name: "Gallery", as: :galleryable accepts_nested_attributes_for arg end end end |