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