5
Các kiểu khác nhau: kiểu mà tôi đã xác định cho đá quý Paperclip để tạo khi tạo hình ảnh đã ngừng hoạt động sau khi nâng cấp. Các tệp đó không được tạo ra, nhưng 'tệp gốc' là (tệp duy nhất).Kẹp giấy không tạo hình thu nhỏ/kiểu/kích cỡ sau khi nâng cấp từ phiên bản đầu lên 3.x (lưu trữ S3)
class Image < ActiveRecord::Base
belongs_to :member
has_many :article_images, :dependent => :destroy
has_many :articles, :through => :article_images
has_many :member_photos, :dependent => :destroy
has_one :member_avatar, :dependent => :destroy
validates_presence_of :member_id
after_validation do |resource|
#since paperclip doesn't give a damn error message like an idiot
resource.errors[:image] = resource.errors[:image_file_name] ? resource.errors[:image_file_name] : resource.errors[:image_content_type]
end
before_save do |resource|
#set name to filename if no name sent
resource.name = resource.image_file_name.split('.')[0].titleize if resource.name.blank?
end
scope :for_slideshow, limit(5)
has_attached_file :image,
:styles => {
:original => "1100x1100", #overwrites orig, for file storage efficiency
:x_large => "900x900",
:large => "600x600",
:medium => "300x300>",
:thumb_1 => "100x100#",
:thumb_2 => "50x50#",
:thumb_3 => "25x25#"
#To refresh image thumbs: rake paperclip:refresh CLASS=Image
},
:storage => :s3,
:path => ":attachment/:id/:style.:extension",
:s3_credentials => "#{::Rails.root}/config/s3.yml"
#:url => "/system/:attachment/:id/:style/:filename"
validates_attachment_content_type :image, :content_type=>['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg', 'image/x-png'] #last two for IE 6-8
validates_attachment_presence :image
#validates_attachment_size :image, :less_than=>1.megabyte
end
Các bản ghi không hiển thị một nỗ lực tại bất cứ điều gì hơn:
SQL (0.3ms) INSERT INTO `images` (`caption`, `created_at`, `desc`, `image_content_type`, `image_file_name`, `image_file_size`, `image_updated_at`, `member_id`, `name`, `updated_at`) VALUES ('', '2013-02-18 06:34:55', '', 'image/jpeg', '525119_10151396740758260_611505697_n.jpeg', 111946, '2013-02-18 06:34:55', 719, '525119 10151396740758260 611505697 N', '2013-02-18 06:34:55')
[paperclip] Saving attachments.
[paperclip] saving images/4201/original.jpeg
[AWS S3 200 1.367095 0 retries] put_object(:acl=>:public_read,:bucket_name=>"mybucket.development/paperclip",:content_length=>111946,:content_type=>"image/jpeg",:data=>Paperclip::UploadedFileAdapter: 525119_10151396740758260_611505697_n.jpeg,:key=>"images/4201/original.jpeg")
tôi thiếu gì?
Tôi có cùng khả năng, bạn có tìm thấy giải pháp nào không? –