Я создаю штрих-код .png в обратном вызове, используя Barby gem :
Isbn.rb:
before_save :barcode
def barcode
barcode = Barby::Bookland.new(self.productidentifier_idvalue)
my_bc = Barcodeimg.new(:isbn_id => self.id)
my_bc.image = File.open("#{self.productidentifier_idvalue}-barcode.png", 'w') do |f|
f.write barcode.to_png
end
my_bc.save!
end
Тогда я надеюсь загрузить его непосредственно в S3 через скрепку: вот модель Barcodeimg.rb:
require 'open-uri'
require "aws/s3"
class Barcodeimg < ActiveRecord::Base
has_attached_file :image,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:s3_protocol => "https",
:path => ":class/:id/:basename_:style.:extension",
:bucket => "bucketname",
:url => ":s3_eu_url"
end
Я знаю, что учетные данные работают, поскольку я использую те же самые настройки в другой модели. Есть идеи, что я делаю не так? Новый экземпляр Barcodeimg сохраняется, но без вложения. Там нет сообщений об ошибках - просто изображение не появляется на S3! Из трассировки стека:
SQL (1.8ms) INSERT INTO "barcodeimgs" ( "created_at", "image_content_type", "image_file_name", "image_file_size", "image_remote_url", "isbn_id", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ["created_at", Tue, 30 Aug 2011 20:26:20 UTC +00:00], ["image_content_type", nil], ["image_file_name", nil], ["image_file_size", nil], ["image_remote_url", nil], ["isbn_id", 7128], ["updated_at", Tue, 30 Aug 2011 20:26:20 UTC +00:00], ["user_id", nil]]
[paperclip] Saving attachments.