Method: Assetable::Base::ClassMethods#galleryable

Defined in:
lib/assetable/active_record/base.rb

#galleryable(*args) ⇒ Object

Galleries



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/assetable/active_record/base.rb', line 28

def galleryable *args
  # By default, let's include a gallery. 
  unless args.include? :gallery
    has_one :gallery, class_name: "Assetabler::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: "Assetabler::Gallery", as: :galleryable
      accepts_nested_attributes_for arg
    end
  end
end