Sha256: d58fbd1c963e05ff9d549b99d455543b0e9f3cf4f4e83d5f63cc5f154ccc8fe1

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

class Image < ActiveRecord::Base

  # Docs for attachment_fu http://github.com/technoweenie/attachment_fu
  has_attachment :content_type => :image,
                 :storage => (USE_S3_BACKEND ? :s3 : :file_system),
                 :path_prefix => (USE_S3_BACKEND ? nil : 'public/system/images'),
                 :processor => 'Rmagick',
                 :thumbnails => ((((thumbnails = RefinerySetting.find_or_set(:image_thumbnails, {})).is_a?(Hash) ? thumbnails : (RefinerySetting[:image_thumbnails] = {}))) rescue {}),
                 :max_size => 50.megabytes

   def validate
     if self.filename.nil?
       errors.add_to_base("You must choose an image to upload")
     else
       [:size, :content_type].each do |attr_name|
         enum = attachment_options[attr_name]
         unless enum.nil? || enum.include?(send(attr_name))
           errors.add_to_base("Images should be smaller than 50 MB in size") if attr_name == :size
           errors.add_to_base("Your image must be either a JPG, PNG or GIF") if attr_name == :content_type
         end
       end
     end
   end

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

  named_scope :thumbnails, :conditions => "parent_id IS NOT NULL"
  named_scope :originals, :conditions => {:parent_id => nil}

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

  # 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

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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
refinerycms-0.9.6.7 vendor/plugins/images/app/models/image.rb