【发布时间】:2015-11-23 19:43:03
【问题描述】:
我在 s3 上存储了一张照片,当我尝试显示照片时,未定义该方法。
为什么 has_attached_file 没有在这里定义 :photo?
我的模特:
has_attached_file :photo,
:styles => { :medium => "300x300>",
:thumb => "100x100>" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/aws.yml",
:s3_region => 'US Standard'
我的控制器:
@products = Store.all
private
def product_params
params.require(:store).permit(:id, :name, :photo)
end
我的看法:
<%= image_tag @products.photo.url %>
我的架构(只是为了显示回形针迁移有效):
create_table "stores", force: :cascade do |t|
t.string "name", limit: 255
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
end
我忘了提一下:我的表单正在使用 :photo 参数将照片保存到我的 S3 存储桶中,它只是没有使用这种方法在我的视图中呈现。
【问题讨论】:
标签: ruby-on-rails amazon-s3 paperclip