Sha256: d3b3bb26a9606f94eb105b195b9780af9e70d280af7e4cb43e01610df8a7edf0

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Spotlight
  ##
  # Exhibit curator contact information
  class Contact < ActiveRecord::Base
    belongs_to :exhibit, touch: true
    scope :published, -> { where(show_in_sidebar: true) }
    default_scope { order('weight ASC') }
    serialize :contact_info, Hash

    extend FriendlyId
    friendly_id :name, use: [:slugged, :scoped, :finders], scope: :exhibit

    mount_uploader :avatar, Spotlight::AvatarUploader

    ## carrierwave-crop doesn't want to store the crop points. we do.
    # so instead of this:
    # crop_uploaded :avatar  ## Add this
    # we do this:
    after_save do
      if avatar.present?
        avatar.cache! unless avatar.cached?
        avatar.store!
        recreate_avatar_versions
      end
    end

    before_save on: :create do
      self.show_in_sidebar = true if show_in_sidebar.nil?
    end

    def self.fields
      @fields ||= { title: { itemprop: 'jobTitle' },
                    location: { itemprop: 'workLocation' },
                    email: { helper: :render_contact_email_address },
                    telephone: {} }
    end

    protected

    def should_generate_new_friendly_id?
      name_changed?
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blacklight-spotlight-0.7.2 app/models/spotlight/contact.rb
blacklight-spotlight-0.7.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.7.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.6.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.5.0 app/models/spotlight/contact.rb