2017-06-19 115 views
0

在我的應用程序中,我想看到幾張照片。我沒有具體的錯誤,但我只看到照片的名稱。使用Carrierwave和Rails 5上傳多張圖片

在我的控制器:

private 

# Use callbacks to share common setup or constraints between actions. 
def set_place 
    @place = Place.find(params[:id]) 
end 

# Never trust parameters from the scary internet, only allow the white list through. 
def place_params 
    params.require(:place).permit(:title, :description, 
           :price,:country,{photos: []}, 
end 

在我的模型:

mount_uploader :photos, PhotoUploader 

在我的形式:

<%= f.file_field :photos, as: :file, multiple: true %> 

在顯示視圖:

<dd><%= image_tag @place.photos_url %></dd> 

我正在使用MySQL數據庫。

+0

請修復問題的格式和添加有關儲蓄的信息的記錄和上傳的文件。什麼不符合你的期望? – mdesantis

+0

我想看幾張照片,但我不工作。 – dalyl

回答

0

相反的mount_uploader,使用mount_uploaders(帶有「S」末)來指定CarrierWave,他將不得不指望幾個文件(doc here

然後當它這樣做,他會給予回覆每個文件的路徑的排列,因此,所有你需要做的是以下幾點:

<dd> 
    <% @place.photos.each do |p| %> 
    <%= image_tag p %> 
    <!-- if this doesn't work, try this --> 
    <%= image_tag p.url %> 
    <% end %> 
</dd> 

我讓如有必要,你適應的代碼,只是告訴我,如果它的工作原理

+0

不起作用,我看到這個''[]''而不是圖像 – dalyl

+0

你在哪裏看到[]? – Jaeger

+0

這是一個應答器alt ..,在代碼源image_tag p.url:Waf dalyl