Paperclip :style depending on model (has_many polymorphic images)

后端 未结 10 920
醉梦人生
醉梦人生 2021-02-03 11:33

I have set up my models to use a polymorphic Image model. This is working fine, however I am wondering if it is possible to change the :styles setting for each model. Found some

10条回答
  •  一生所求
    2021-02-03 12:20

    class Banner < ActiveRecord::Base  
    
      belongs_to :banner_categoria
      validates :banner_categoria_id ,{:presence =>{:message => "não informada"}} 
    
      has_attached_file :arquivo
      after_initialize :init_attachment
    
    
    
    
      def init_attachment
        self.class.has_attached_file :arquivo,
          :url => "/system/:class/:attachment/:id/:style/:basename.:extension",
          :path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension",
          :styles => hash = {
          :banner => {
            :geometry => "#{self.banner_categoria.largura}x#{self.banner_categoria.altura}>",
            :quality => 80
          },
          :thumb => "100x100#"
        }
      end
    

    end

提交回复
热议问题