Paperclip - Default Style per Style? Possible

怎甘沉沦 提交于 2019-12-05 14:33:28

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!