Class: Gluttonberg::AssetCollection

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gluttonberg/asset_collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.process_new_collection_and_merge(params, current_user) ⇒ Object

if new collection is provided it will create the object for that then it will add new collection id into other existing collection ids



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/gluttonberg/asset_collection.rb', line 28

def self.process_new_collection_and_merge(params, current_user)
  collection_ids = params[:asset][:asset_collection_ids]
  if collection_ids.blank? || ["null", "undefined"].include?(collection_ids)
    collection_ids = []
  end
  if collection_ids.kind_of?(String)
    collection_ids = collection_ids.split(",")
  end
  the_collection = find_or_create_asset_collection_from_hash(params[:new_collection], current_user)
  unless the_collection.blank?
    collection_ids <<  the_collection.id
  end
  params[:asset][:asset_collection_ids] = collection_ids
end

Instance Method Details

#imagesObject

Find all images within collection



16
17
18
19
# File 'app/models/gluttonberg/asset_collection.rb', line 16

def images
  data = assets.includes([:asset_type]).all
  data.find_all{|d| d.category == "image"}
end

#name_with_number_of_imagesObject

this method is required for gallery form



22
23
24
# File 'app/models/gluttonberg/asset_collection.rb', line 22

def name_with_number_of_images
  "#{name} (#{images.length} images)"
end