Sha256: d89db1ad308120eb6e3668ab3d3c4dd95b823aa45b35c251e89cca7af8b03595

Contents?: true

Size: 1.26 KB

Versions: 35

Compression:

Stored size: 1.26 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?
      super || (name_changed? && persisted?)
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
blacklight-spotlight-0.32.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.31.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.30.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.29.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.29.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.28.3 app/models/spotlight/contact.rb
blacklight-spotlight-0.28.2 app/models/spotlight/contact.rb
blacklight-spotlight-0.28.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.28.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.27.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.26.1 app/models/spotlight/contact.rb
blacklight-spotlight-0.26.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.25.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.24.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.23.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.22.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.21.0 app/models/spotlight/contact.rb
blacklight-spotlight-0.20.3 app/models/spotlight/contact.rb
blacklight-spotlight-0.20.2 app/models/spotlight/contact.rb
blacklight-spotlight-0.20.1 app/models/spotlight/contact.rb