Sha256: d09b9d793987b60a38841bd0d611a8e8fc179bd02a40dfe4de2ae9c18d161320

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 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

    before_save do
      self.contact_info = contact_info.symbolize_keys
    end

    ## 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

11 entries across 11 versions & 1 rubygems

Version Path
blacklight-spotlight-0.11.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.10.3 app/models/spotlight/contact.rb
blacklight-spotlight-0.10.2 app/models/spotlight/contact.rb
blacklight-spotlight-0.10.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.10.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.9.2 app/models/spotlight/contact.rb
blacklight-spotlight-0.9.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.9.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.8.2 app/models/spotlight/contact.rb
blacklight-spotlight-0.8.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.8.0 app/models/spotlight/contact.rb