开发者

How do I add a conditional to certain paperclip styles?

I have a model called Graphic, each graphic belongs_to one model c开发者_如何学编程alled Book, the graphic model has 1 style and I want to add a 2nd one called "dealer_logo":

:thumb       => ['75x75>],
:dealer_logo => ['200x45>', :jpg], :if => Proc.new {|file| Book.find(self.book_id).origin_id == 33}

I only want the dealer_logo style to get generated however if the Book.origin_id is equal to 33, however I cannot get the above code to work.

Can anyone give me any pointers?

Thanks


You'll need to use a custom processor: https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/processor.rb

By defining a subclass of Paperclip::Processor, you can perform any processing you want on the files that are attached. Any file in your Rails app’s lib/paperclip_processors directory is automatically loaded by paperclip, allowing you to easily define custom processors. You can specify a processor with the :processors option to has_attached_file:

has_attached_file :scan, :styles => { :text => { :quality => :better } },
                       :processors => [:ocr]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜