app/models/spotlight/exhibit.rb in blacklight-spotlight-0.0.1 vs app/models/spotlight/exhibit.rb in blacklight-spotlight-0.0.2

- old
+ new

@@ -5,24 +5,29 @@ has_many :searches has_many :about_pages has_many :feature_pages has_one :home_page has_many :home_pages + has_many :users, through: :roles, class_name: '::User' + has_many :custom_fields belongs_to :blacklight_configuration, class_name: Spotlight::BlacklightConfiguration accepts_nested_attributes_for :blacklight_configuration accepts_nested_attributes_for :searches accepts_nested_attributes_for :about_pages accepts_nested_attributes_for :feature_pages + accepts_nested_attributes_for :roles, allow_destroy: true delegate :blacklight_config, to: :blacklight_configuration serialize :facets, Array serialize :contact_emails, Array + after_create :add_default_home_page before_save :sanitize_description validate :name, :title, presence: true validate :valid_emails + acts_as_tagger # This is necessary so the form will draw as if we have nested attributes (fields_for). def contact_emails super.each do |e| def e.persisted? @@ -61,9 +66,13 @@ parsed = Mail::Address.new(email) rescue Mail::Field::ParseError => e end errors.add :contact_emails, "#{email} is not valid" unless !parsed.nil? && parsed.address == email && parsed.local != email #cannot be a local address end + end + + def add_default_home_page + Spotlight::HomePage.create(exhibit: self).save end def sanitize_description self.description = HTML::FullSanitizer.new.sanitize(description) if description_changed? end