Module | Paperclip::ClassMethods |
In: |
lib/paperclip.rb
|
Returns the attachment definitions defined by each call to has_attached_file.
has_attached_file gives the class it is called on an attribute that maps to a file. This is typically a file stored somewhere on the filesystem and has been uploaded by a user. The attribute returns a Paperclip::Attachment object which handles the management of that file. The intent is to make the attachment as much like a normal attribute. The thumbnails will be created when the new file is assigned, but they will not be saved until save is called on the record. Likewise, if the attribute is set to nil is called on it, the attachment will not be deleted until save is called. See the Paperclip::Attachment documentation for more specifics. There are a number of options you can set to change the behavior of a Paperclip attachment:
:url => "/:class/:attachment/:id/:style_:filename" :url => "http://some.other.host/stuff/:class/:id_:extension"
has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png" User.new.avatar_url(:small) # => "/images/default_small_avatar.png"
has_attached_file :avatar, :styles => { :normal => "100x100#" }, :default_style => :normal user.avatar.url # => "/avatars/23/normal_me.png"
has_attached_file :avatar, :styles => { :large => "300x300", :negative => "100x100" } :convert_options => { :all => "-strip", :negative => "-negate" }
NOTE: While not deprecated yet, it is not recommended to specify options this way. It is recommended that :convert_options option be included in the hash passed to each :styles for compatibility with future versions. NOTE: Strings supplied to :convert_options are split on space in order to undergo shell quoting for safety. If your options require a space, please pre-split them and pass an array to :convert_options instead.
It‘s also possible for you to dynamically define your interpolation string for :url, :default_url, and :path in your model by passing a method name as a symbol as a argument for your has_attached_file definition:
class Person has_attached_file :avatar, :default_url => :default_url_by_gender private def default_url_by_gender "/assets/avatars/default_#{gender}.png" end end
Places ActiveRecord-style validations on the content type of the file assigned. The possible options are:
NOTE: If you do not specify an [attachment]_content_type field on your model, content_type validation will work _ONLY upon assignment_ and re-validation after the instance has been reloaded will always succeed. You‘ll still need to have a virtual attribute (created by attr_accessor) name +[attachment]_content_type+ to be able to use this validator.
Places ActiveRecord-style validations on the presence of a file. Options:
Places ActiveRecord-style validations on the size of the file assigned. The possible options are: