2017-01-07 23 views
0

如果圖像存儲在資源/圖像/ Garden3.jpeg中,如何使用回形針調出圖像?我添加的記錄自己使用Rails控制檯,以下是在DB值:回形針加載資產/圖像目錄中的圖像

#<Product id: 1, product_code: "FB_60", product_description: "Fruits: Apple,Orange,Banana Flowers: Zebra, Chrysa...", price: #<BigDecimal:7f9ec73ec430,'0.6E2',9(18)>, product_image_file_name: "Garden3.jpeg", product_image_content_type: "jpeg", product_image_file_size: nil, product_image_updated_at: nil, category_id: 1> 

我在目錄中有資產/圖像/ Garden3.jpeg的圖像。產品型號會加載圖片並顯示圖片,價格&詳情。在我的產品型號,我有:

class Product < ActiveRecord::Base 
    belongs_to :category 

    has_attached_file :product_image, styles: { small: "64x64", med: "100x100", large: "200x200" }, 
    :url => "/system/products/product_images/000/000/:id/:style/:basename.:extension", 
    :path => ":rails_root/app/assets/images/:basename:extension" 

end 

我也允許帕拉姆名稱:在控制器product_image。然而,當我運行的應用程序,也沒有除了圖像圖標顯示任何圖像:

enter image description here

可我知道我該怎麼處理這個問題?非常感謝,如果我可以對它進行一些解釋來改進它,我會很感激。

回答

0

甚至當我將我的rails應用程序部署到Heroku時,我也面臨類似的問題。 經過大量的嘗試,爲我工作的東西是我試圖刪除文件名的擴展名。在你的情況下:

Save data row as `#<Product id: 1, product_code: "FB_60", product_description: "Fruits: Apple,Orange,Banana Flowers: Zebra, Chrysa...", price: #<BigDecimal:7f9ec73ec430,'0.6E2',9(18)>, product_image_file_name: "Garden3", product_image_content_type: "jpeg", product_image_file_size: nil, product_image_updated_at: nil, category_id: 1>` 

希望它適用於你,否則嘗試播放文件名的擴展名。

`