Module: Bootsy::Container

Extended by:
ActiveSupport::Concern
Defined in:
lib/bootsy/container.rb

Overview

Public: Methods and attributes to turn any model into a Bootsy Container.

Examples

class Post < ActiveRecord::Base
  include Bootsy::Container
end

Instance Method Summary collapse

Instance Method Details

Public: Get the ‘id` attribute of the image gallery.

Returns an Integer id or nil when there is not an image gallery.



25
26
27
# File 'lib/bootsy/container.rb', line 25

def bootsy_image_gallery_id
  bootsy_image_gallery.try(:id)
end

Public: Set the image gallery ‘id` and save the association between models.

Examples

container.id
# => 34
gallery.id
# => 12
container.bootsy_image_gallery_id = gallery.id
container.image_gallery_id
# => 12
gallery.bootsy_resource.id
# => 34


43
44
45
46
47
48
49
50
51
# File 'lib/bootsy/container.rb', line 43

def bootsy_image_gallery_id=(value)
  if bootsy_image_gallery.nil? && value.present?
    self.bootsy_image_gallery = Bootsy::ImageGallery.find(value)
    bootsy_image_gallery.bootsy_resource = self
    bootsy_image_gallery.save
  else
    value
  end
end