app/models/spotlight/search.rb in blacklight-spotlight-0.8.0 vs app/models/spotlight/search.rb in blacklight-spotlight-0.8.1

- old
+ new

@@ -1,9 +1,10 @@ module Spotlight ## # Exhibit saved searches class Search < ActiveRecord::Base + include DefaultThumbnailable extend FriendlyId friendly_id :title, use: [:slugged, :scoped, :finders, :history], scope: :exhibit self.table_name = 'spotlight_searches' belongs_to :exhibit @@ -16,12 +17,10 @@ belongs_to :masthead, dependent: :destroy belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy accepts_nested_attributes_for :thumbnail, update_only: true accepts_nested_attributes_for :masthead, update_only: true - before_create :set_default_featured_image - include Blacklight::SearchHelper include Spotlight::Catalog::AccessControlsEnforcement def thumbnail_image_url thumbnail.image.thumb.url if thumbnail && thumbnail.image @@ -53,10 +52,23 @@ def display_masthead? masthead && masthead.display? end + def set_default_thumbnail + self.thumbnail ||= begin + doc = documents.detect { |x| x.first(Spotlight::Engine.config.full_image_field) } + if doc + create_thumbnail( + source: 'exhibit', + document_global_id: doc.to_global_id.to_s, + remote_image_url: doc.first(Spotlight::Engine.config.full_image_field) + ) + end + end + end + private def solr_response @solr_response ||= repository.search( search_builder.with(query_params).rows(1000).merge( @@ -75,18 +87,9 @@ ] end def should_generate_new_friendly_id? title_changed? - end - - def set_default_featured_image - self.thumbnail ||= begin - doc = documents.detect { |x| x.first(Spotlight::Engine.config.full_image_field) } - if doc - create_thumbnail source: 'exhibit', document_global_id: doc.to_global_id.to_s, remote_image_url: doc.first(Spotlight::Engine.config.full_image_field) - end - end end alias_method :current_exhibit, :exhibit end end