app/models/spotlight/exhibit.rb in blacklight-spotlight-0.1.0 vs app/models/spotlight/exhibit.rb in blacklight-spotlight-0.2.0

- old
+ new

@@ -33,11 +33,11 @@ accepts_nested_attributes_for :main_navigations accepts_nested_attributes_for :contacts accepts_nested_attributes_for :contact_emails, reject_if: proc {|attr| attr['email'].blank?} accepts_nested_attributes_for :roles, allow_destroy: true, reject_if: proc {|attr| attr['user_key'].blank?} accepts_nested_attributes_for :custom_fields - accepts_nested_attributes_for :attachments + accepts_nested_attributes_for :resources delegate :blacklight_config, to: :blacklight_configuration serialize :facets, Array @@ -45,12 +45,20 @@ after_create :initialize_config after_create :initialize_browse after_create :initialize_main_navigation before_save :sanitize_description - validate :title, presence: true + after_destroy do + # Touch the default exhibit to ensure caching knows that + # the exhibits have changed. + Spotlight::Exhibit.default.touch + end + + validates :title, presence: true acts_as_tagger + has_many :owned_taggings, class_name: "ActsAsTaggableOn::Tagging", as: :tagger + accepts_nested_attributes_for :owned_taggings def main_about_page @main_about_page ||= about_pages.published.first end @@ -70,14 +78,22 @@ end def import hash # remove the default browse category -- it might be in the import # and we don't want to have a conflicting slug - - if persisted? - searches.where(title: "All Exhibit Items").destroy_all + if persisted? and hash.fetch("searches_attributes", []).any? { |x| x["slug"] == "all-exhibit-items"} + searches.where(slug: "all-exhibit-items").destroy_all reload end + + if hash["owned_taggings_attributes"] + hash["owned_taggings_attributes"].each do |tagging| + tag = tagging.delete "tag_attributes" + tagging["context"] = "tags" + tagging["tag"] = ActsAsTaggableOn::Tag.find_or_create_by name: tag["name"] + end + end + update hash end protected