Paperclip :style depending on model (has_many polymorphic images)

后端 未结 10 956
醉梦人生
醉梦人生 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:19

    I liked MarkGranoff's answer but I came up with a much simpler implementation that does the trick for me and seems more maintainable.

    #create new and instantiate the fields you need ( or all except the attachment )
    @photo = Photo.new(:attribution => params[:photo][:attribution],
                       :latitude => params[:photo][:latitude ])
    
    #then just assign all params as normal
    @photo = Photo.assign_attributes(params[:node])
    

    The second statement assigns the attachment so the processor is fired, and since you've already assigned :attribution and :latitude, their values will be available in the processor via the attachment.instance method.

    Thanks everyone here for the insight!

提交回复
热议问题