1
我安装的宝石:https://github.com/benmanns/tinypng轨回形针tinypng宝石
而且在我的课:
has_attached_file :photo <...>
before_save :tiny_png_preprocessor
private
def tiny_png_preprocessor
image_file = File.open(self.photo.path)
client = TinyPNG::Client.new("#{tiny_png_api_key}") # tinypng api key
image = client.shrink(image_file.read)
image.input # => {"size"=>1234}
image.output # => {"depth"=>8, "size"=>567, "ratio"=>0.459, "url"=>"http://tinypng.org/api/shrink/out/example.png"}
temp_file = image.to_file # => #<File:/tmp/tinypng20120910-5552-aturxh.png>
self.photo = temp_file
end
我想rake paperclip:refresh class=Photo
用于预处理的所有照片后,回形针保存。我怎样才能做到这一点?
在rake任务后,我的控制台:
rake aborted!
ArgumentError: wrong number of arguments (1 for 0)
/mtfck/new_tamir/app/models/photo.rb:30:in 'initialize'
/mtfck/new_tamir/app/models/photo.rb:30:in 'new'
/mtfck/new_tamir/app/models/photo.rb:30:in 'tiny_png_preprocessor'
我有tiny_png_api_key。只是隐藏它。因为我想要支付专业帐户小小的PNG。对不起,如果它误导了你。 – Legendary 2015-02-09 15:02:13
@Legendary,我要说的是,确保你的密钥进入。在密钥 – AnkitG 2015-02-09 15:03:15
上执行'logger.info'我有| client = TinyPNG :: Client.new('API_KEY_STRING_HERE')|没有变数 – Legendary 2015-02-09 15:04:44