Class: Spotlight::Exhibit

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spotlight/exhibit.rb

Constant Summary collapse

DEFAULT =
'default'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject

Find or create the default exhibit



52
53
54
55
56
57
# File 'app/models/spotlight/exhibit.rb', line 52

def self.default
  self.find_or_create_by!(name: DEFAULT) do |e|
    e.title = 'Default exhibit'.freeze
    e.blacklight_configuration = Spotlight::BlacklightConfiguration.create!
  end
end

Instance Method Details

#contact_emailsObject

This is necessary so the form will draw as if we have nested attributes (fields_for).



33
34
35
36
37
38
39
# File 'app/models/spotlight/exhibit.rb', line 33

def contact_emails
  super.each do |e|
    def e.persisted?
      false
    end
  end
end

#contact_emails_attributes=(emails) ⇒ Object

The attributes setter is required so the form will draw as if we have nested attributes (fields_for)



42
43
44
45
# File 'app/models/spotlight/exhibit.rb', line 42

def contact_emails_attributes=(emails)
  attributes_collection = emails.is_a?(Hash) ? emails.values : emails
  self.contact_emails = attributes_collection.map {|e| e['email']}.reject(&:blank?)
end

#has_browse_categories?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/spotlight/exhibit.rb', line 59

def has_browse_categories?
  searches.published.any?
end

#main_about_pageObject



47
48
49
# File 'app/models/spotlight/exhibit.rb', line 47

def main_about_page
  @main_about_page ||= about_pages.published.first
end