Sha256: 2cabb4c486ff2c36ffaca1ae9ff03a6370e8e09fbbc142b5d420b9ec61696ff5

Contents?: true

Size: 1.84 KB

Versions: 19

Compression:

Stored size: 1.84 KB

Contents

class Resource < ActiveRecord::Base

  # What is the max resource size a user can upload
  MAX_SIZE_IN_MB = 50

  # Docs for attachment_fu http://github.com/technoweenie/attachment_fu
  has_attachment :storage => (Refinery.s3_backend ? :s3 : :file_system),
                 :max_size => MAX_SIZE_IN_MB.megabytes,
                 :path_prefix => (Refinery.s3_backend ? nil : 'public/system/resources')

  # we could use validates_as_attachment but it produces 4 odd errors like
  # "size is not in list". So we basically here enforce the same validation
  # rules here except display the error messages we want
  # This is a known problem when using attachment_fu
  def validate
    if self.filename.nil?
      errors.add_to_base("You must choose a file to upload")
    else
      [: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 #{MAX_SIZE_IN_MB} MB in size") if attr_name == :size
        end
      end
    end
  end

  # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
  acts_as_indexed :fields => [:title, :type_of_content],
                  :index_file => [Rails.root.to_s, "tmp", "index"]

  # when a dialog pops up with images, how many images per page should there be
  PAGES_PER_DIALOG = 12

  # when listing images out in the admin area, how many images should show per page
  PAGES_PER_ADMIN_INDEX = 20

  # How many images per page should be displayed?
  def self.per_page(dialog = false)
    dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
  end

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

  # Returns a titleized version of the filename
  # my_file.pdf returns My File
  def title
    CGI::unescape(self.filename).gsub(/\.\w+$/, '').titleize
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.33 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.32 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.31 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.30 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.29 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.28 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.27 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.26 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.25 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.24 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.23 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.22 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.21 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.19 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.18 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.17 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.16 vendor/plugins/resources/app/models/resource.rb
refinerycms-0.9.6.15 vendor/plugins/resources/app/models/resource.rb