Module: ActiveRecord::Acts::UploaderUpload::ClassMethods
- Defined in:
- lib/active_record/acts/uploader_upload.rb
Instance Method Summary collapse
-
#acts_as_uploader(options) ⇒ Object
acts_as_uploader requires an option for :has_attached_file.
Instance Method Details
#acts_as_uploader(options) ⇒ Object
acts_as_uploader requires an option for :has_attached_file. These values will be passed to paperclip. i.e. acts_as_uploader :has_attached_file => { :url => “/uploads/:class/:id/:style_:basename.:extension”, :path => “:rails_root/public/uploads/:class/:id/:style_:basename.:extension”, :styles => { :icon => “30x30!”, :thumb => “100>”, :small => “150>”, :medium => “300>”, :large => “660>”}, :default_url => “/images/profile_default.jpg” }
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_record/acts/uploader_upload.rb', line 18 def acts_as_uploader() #Named scopes named_scope :newest_first, :order => "created_at DESC" named_scope :alphabetic, :order => "filename DESC" named_scope :recent, :order => "created_at DESC" named_scope :public, :conditions => 'is_public = true' named_scope :images, :conditions => "local_content_type IN (#{Uploader::MimeTypeGroups::IMAGE_TYPES.collect{|type| "'#{type}'"}.join(',')})" named_scope :documents, :conditions => "local_content_type IN (#{(Uploader::MimeTypeGroups::WORD_TYPES + Uploader::MimeTypeGroups::EXCEL_TYPES + Uploader::MimeTypeGroups::PDF_TYPES).collect{|type| "'#{type}'"}.join(',')})" named_scope :files, :conditions => "local_content_type NOT IN (#{Uploader::MimeTypeGroups::IMAGE_TYPES.collect{|type| "'#{type}'"}.join(',')})" named_scope :since, lambda { |*args| { :conditions => ["created_at > ?", (args.first || 7.days.ago.to_s(:db)) ]} } named_scope :pending_s3_migration, lambda { { :conditions => ["remote_file_name IS NULL AND created_at <= ?", 20.minutes.ago.to_s(:db)], :order => 'created_at DESC' } } # Paperclip has_attached_file :local, [:has_attached_file].merge(:storage => :filesystem) # Override any storage settings. This one has to be local. if [:enable_s3] == true has_attached_file :remote, [:has_attached_file].merge(:url => ':s3_alias_url', :path => [:s3_path], :storage => :s3) end belongs_to :uploadable, :polymorphic => true belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' class_eval <<-EOV validates_attachment_size :local, :less_than => 10.megabytes before_post_process :transliterate_file_name before_create :add_width_and_height # prevents a user from submitting a crafted form that bypasses activation attr_protected :creator_id, :uploadable_id, :uploadable_type EOV include ActiveRecord::Acts::UploaderUpload::InstanceMethods extend ActiveRecord::Acts::UploaderUpload::SingletonMethods end |