问题
I'm using paperclip, and have several styles:
:styles => {:large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>" }
The issue is default_stype, only applies to one of the sizes... :default_style => :thumb, :default_url => url here....
How can I set default_stypes for each style type? so if I call: <%= image_tag @user.profile_pic.url(:large) %>
The LARGE style has a default_url?
Thanks
回答1:
I Would suggest to use
has_attached_file :xyz, :url => "/assets/:id", :path => ":rails_root/assets/photos/:attachable_type/:attachable_id/:id/:basename_:style.:extension",
:styles => { :large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>"}
and to get the proper style
/assets/:id?style=:style
like localhost:3000/assets/10?style=medium
Note: attacheable_type, attachable_id are coming from the polymorphic relations..
Hope it helps...
rgds,
Kannan R
回答2:
It's fairly easy. Just create paperclip.rb in your /config/initializers and put something like this in there:
module Paperclip
class Attachment
def self.default_options
@default_options ||= {
:url => "/system/:class/:id/:style_:filename",
:path => ":rails_root/public:url",
:styles => {},
:processors => [:thumbnail],
:convert_options => {},
:default_url => "/images/missing/:class_:attachment_:style.jpg",
:default_style => :original,
:storage => :filesystem,
:whiny => Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails]
}
end
end
end
This overrides the defaults. So you can go ahead and change :default_style to whatever you want.
来源:https://stackoverflow.com/questions/3920349/paperclip-default-style-per-style-possible