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


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

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

Parameters:

  • a (ActionController::Parameters)

    collection of nested perameters


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

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