试图让Paperclip刷新或重新处理不起作用

Tri*_*rip 28 rake ruby-on-rails paperclip

我随着时间的推移,改变了大小的交易大小.通过这些更改,用户上传到网站,因此很少有人拥有不同大小的拇指.我想重新压缩或刷新这些,所以我进入我的根并输入:

rake paperclip:refresh class=Deal
Run Code Online (Sandbox Code Playgroud)

没有为拇指大小做任何事情..然后我在脚本/控制台:

Deal.find(987).reprocess!

回复此:

NoMethodError: undefined method `reprocess!' for #<Deal:0xb68a0988>
from /data/HQ_Channel/releases/20100607130346/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:260:in `method_missing'
from (irb):7
Run Code Online (Sandbox Code Playgroud)

我的交易课是这样的:

=> Deal(id: integer, organization_id: integer, deal: string, value: string, what: string, description: string, image_file_name: string, image_content_type: string, image_file_size: integer, image_updated_at: datetime, created_at: datetime, updated_at: datetime, deal_image_file_name: string, deal_image_content_type: string, deal_image_file_size: integer, deal_image_uploaded_at: datetime)
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能让它重新处理原件,使拇指在当前拇指大小参数中的大小正确?

更新:我发现附件包含在Paperclip中.有趣的是方法喜欢.save.updated_at工作.但是reprocess!其他一些方法却没有.有什么味道明显不合适吗?

Tri*_*rip 66

得到它了!

这是因为paperclip与Model的对象无关,而是Model对象的图像.所以写得恰到好处,它会像这样工作:

Model.find(#).image.reprocess!
Run Code Online (Sandbox Code Playgroud)

  • Model.find_each {| thing | thing.image.reprocess!} (17认同)

Und*_*ion 10

您还可以使用包含的Rake任务:

$ rake paperclip:refresh CLASS=Deal
Run Code Online (Sandbox Code Playgroud)

请参阅Paperclip Wiki