Class: FeaturedWorkList

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/featured_work_list.rb

Instance Method Summary collapse

Instance Method Details



16
17
18
19
20
21
22
23
# File 'app/models/featured_work_list.rb', line 16

def featured_works
  return @works if @works
  @works = FeaturedWork.all
  add_solr_document_to_works
  @works = @works.reject do |work|
    work.presenter.blank?
  end
end

Parameters:

  • a (ActionController::Parameters)

    collection of nested perameters



6
7
8
9
10
11
12
13
14
# File 'app/models/featured_work_list.rb', line 6

def featured_works_attributes=(attributes_collection)
  attributes_collection = attributes_collection.to_h if attributes_collection.respond_to?(:permitted?)
  attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes } if attributes_collection.is_a? Hash
  attributes_collection.each do |attributes|
    raise "Missing id" if attributes['id'].blank?
    existing_record = FeaturedWork.find(attributes['id'])
    existing_record.update(attributes.except('id'))
  end
end