在启用舒适的应用中未在自定义模型中获得任何结果。我有一个具有舒适墨西哥沙发后端的模型,它包含一个要上传到AWS的文件。有一个存储桶,我已经配置了各种点:
aws.yml:
development:
access_key_id: 'xxxxxxxxx'
secret_access_key: 'xxxxxxxxx'
development.rb:
config.paperclip_defaults = {
:storage => :s3,
:bucket => 'somerton'
}
model(Drawing.rb):
has_attached_file :image
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
我使用回形针生成器生成了模型,模式是
schema.rb:
create_table "drawings", force: :cascade do |t|
t.string "url"
t.string "title"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
表单partial已被修改为包含文件输入,并且是multipart:
_form.html.haml:
= form.text_field :url
= form.text_field :title
= form.text_field :description
= form.file_field :image
= form.form_group :class => 'form-actions' do
= form.submit :class => 'btn btn-primary'
有人看到我遗漏的明显问题吗? (是的,安装了gem):
gem "paperclip", "~> 4.3" # uploads
gem 'aws-sdk' # allow use of aws for upload storage
当我更新记录时,我可以使用文件输入选择文件,但相关组件的列是空的:
--- !ruby/object:Drawing
raw_attributes:
id: 1
url: blah blah
title: My new thing
description: Dog's Breakfast
created_at: '2015-10-15 20:02:03.848104'
updated_at: '2015-10-15 20:02:33.344581'
image_file_name:
image_content_type:
image_file_size:
image_updated_at:
...