0
我有一張照片存儲在s3上,當我試圖顯示一張照片時,該方法沒有定義。回形針,得到「未定義的方法錯誤」:照片
爲什麼has_attached_file沒有定義:照片在這裏?
我的模型:
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
我忘了提及:我的表單正在使用照片參數將照片保存到S3存儲桶中,這只是在我的視圖中不使用此方法呈現。
得到的照片其實我在商店模式......我只是有商店的@products實例。 – MarkD
請看我更新的答案對不起 –
你真了不起!謝謝!我知道這是一個數組,但不確定回形針在做什麼 – MarkD