Sha256: 3284fda9c5924cc1cce8447e19e061edf79a4825dc747c875f300fe6206da2fd

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Ecm
  module Downloads
    class Download < ActiveRecord::Base
      # acts as list
      acts_as_list scope: :download_category

      # acts as published
      include ActsAsPublished::ActiveRecord
      acts_as_published

      # associations
      belongs_to :download_category,
               inverse_of: :downloads

      # attibutes
      attr_accessible :asset,
                    :description,
                    :download_category_id,
                    :name if respond_to? :attr_accessible

      # callbacks
      before_update :fix_updated_position, if: proc { |d| !position.blank? && d.category_id_changed? }

      # friendly id
      extend FriendlyId
      friendly_id :name, use: [:slugged]

      # paperclip
      has_attached_file :asset, Ecm::Downloads::Configuration.paperclip_options

      # validations
      validates :download_category, presence: true
      validates :name, presence: true
      validates_attachment :asset, presence: true
      do_not_validate_attachment_file_type :asset

      def human
      name
      end

      def to_s
      human
      end

      private

      def fix_updated_position
        Rails.logger.debug "Fixing positions for #{self} (Moving to last)"
        add_to_list_bottom
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ecm_downloads2-5.0.0 app/models/ecm/downloads/download.rb
ecm_downloads2-4.0.1 app/models/ecm/downloads/download.rb