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



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

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
14
15
# File 'app/models/featured_work_list.rb', line 5

def featured_works_attributes=(attributes_collection)
  if attributes_collection.respond_to?(:permitted?)
    attributes_collection = attributes_collection.to_h
  end
  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