[英]Paperclip displaying multiple file uploads
我有多個文件正在使用回形針上載,但是我無法顯示它們。 這是我正在嘗試的:
楷模):
class Attach < ActiveRecord::Base
attr_accessible :protocol_id, :file
has_attached_file :file,
:path => ':rails_root/public/system/attachs/files/000/000/0:id/original/:basename.:extension'
attr_accessible :file_file_name, :file_content_type, :file_file_size
validates_attachment_presence :file
belongs_to :protocol
end
class Protocol < ActiveRecord::Base
attr_accessible :current_approved, :p_irb_apn, :past_approved, :attachs_attributes
has_many :attachs
accepts_nested_attributes_for :attachs, :allow_destroy => true
end
我的控制器的一部分:
def new
@protocol = Protocol.new
@protocol.attachs.build
respond_to do |format|
format.html # new.html.erb
format.json { render json: @protocol }
end
end
我在其中存儲圖像的表單的一部分:
<div class="field">
<%= f.label :file, "Mod" %>
<%= file_field_tag('protocol_attachs_attributes_file', multiple: true, name: "protocol[attachs_attributes][][file]") %>
</div>
我的節目:
<p>
<b>Modification:</b>
<% for attach in @protocol.attachs %>
<%= link_to "Download", @protocol.attachs.url(:original)%>
<% end %>
</p>
每次上傳時,我都會一遍又一遍地獲得相同的文件(即使它是不同的文件)。 誰能協助我解決這個問題?
您正在迭代,但是為每個附件鏈接運行相同的代碼。
使用規范的Ruby,它將更接近:
<% @protocol.attachs.each do |attach| %>
<%= link_to "Download", attach.url(:original) %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.