2011-03-01 58 views
0

我對Rails很陌生,正在開發我的第一個Rails 3項目。 I watched Multiple File Uploads With Paperclip by Emerson Lackey並完全按照它。我有我的編輯/新形式正常工作,並顯示每個上傳文件的縮略圖。現在,在我的index.html.erb文件中,我只想顯示爲每個項目上傳的第一個縮略圖。這裏就是我想要做的事:如何只在索引上顯示一個縮略圖?

<% for art_item in @art_items %> 
<tr class="<%= cycle("even", "odd") %>"> 
    <td><%= image_tag art_item.assets[0].url(:thumb) %></td> 
    <td><%= art_item.title %></td> 
</tr> 

<%結束%>

如果每個art_item有多達5張(資產)。

顯然我不知道我在做什麼,因爲我得到一個「未定義的方法`url」「錯誤。我是否必須使用部分圖像並將所有圖像作爲集合傳遞?

多一點,如果它是有幫助的:

class Asset < ActiveRecord::Base 
    belongs_to :art_item 
    has_attached_file :asset, :styles => { :large => "640x480", :medium => "300x300>", :thumb => "100x100>" } 
end 
+0

請只使用標籤來「標記」您的文章,而不是把他們的稱號也。 – 2011-03-01 04:26:46

+0

gotcha。我會記住的。 – panzhuli 2011-03-01 16:43:53

回答

1

試試這個:art_item.assets[0].asset.url(:thumb)

+0

完美 - 謝謝! – panzhuli 2011-03-01 16:43:23