", :medium => "150x150>", :...">

Paperclip - default style for style? Possible

I use paperclip and have several styles:

:styles => {:large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>" } 

The problem is default_stype, it applies only to one of the sizes ...: default_style =>: thumb,: default_url => url here ....

How can I set default_stypes for each type of style? so if I call: <% = image_tag @ user.profile_pic.url (: large)%>

Is the LARGE style set to default_url?

thanks

+4
source share
2 answers

I suggest using

 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 get the right style

/ assets /: identifier style =: style

like localhost: 3000 / assets / 10? style = medium

Note: attacheable_type, attachable_id come from polymorphic relationships.

Hope this helps ...

Rgds,

Kannan r

+3
source

This is pretty easy. Just create paperclip.rb in your / config / initializers and put something like this 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 default values. So you can go and change: default_style to whatever you want.

+4
source

All Articles