[英]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.