Sha256: c34511e1df2db5fb400da281d3c5247430da08bde55e9ec9a465027646c2485a

Contents?: true

Size: 903 Bytes

Versions: 16

Compression:

Stored size: 903 Bytes

Contents

class Resource < ActiveRecord::Base

  has_attachment :storage => :file_system,
          :size => 0.kilobytes..50.megabytes,
          :path_prefix => 'public/system/resources'

  acts_as_indexed :fields => [:title, :type_of_content]

  def validate
    errors.add_to_base("You must choose a file to upload") unless self.filename

    unless self.filename.nil?
      [:size].each do |attr_name|
        enum = attachment_options[attr_name]
        unless enum.nil? || enum.include?(send(attr_name))
          errors.add_to_base("Files should be smaller than 50 MB in size")
        end
      end
    end

  end

  # used for searching
  def type_of_content
    self.content_type.split("/").join(" ")
  end

  def title
    (split_filename = self[:filename].split('.')).pop and return split_filename.join('.').titleize
  end

  def self.per_page(dialog = false)
    size = (dialog ? 12 : 20)
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
refinerycms-0.9.5.29 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.28 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.27 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.26 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.25 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.24 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.23 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.22 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.21 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.20 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.19 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.18 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.17 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.16 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.15 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.5.14 vendor/plugins/resources/app/models/resource.rb