Ruby on rails 显示多个文件上载的回形针
我用回形针上传了多个文件,但我在显示这些文件时遇到了问题。以下是我正在尝试的: 型号: 我存储图像的表单的一部分:Ruby on rails 显示多个文件上载的回形针,ruby-on-rails,Ruby On Rails,我用回形针上传了多个文件,但我在显示这些文件时遇到了问题。以下是我正在尝试的: 型号: 我存储图像的表单的一部分: <div class="field"> <%= f.label :file, "Mod" %> <%= file_field_tag('protocol_attachs_attributes_file', multiple: true, name: "protocol[attachs_attributes][][file]") %
<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>
修改:
每次上传时,我都会一遍又一遍地收到相同的文件(即使是不同的文件)。有人能帮我解决这个问题吗?您正在迭代,但为每个附件链接运行相同的代码 使用canonical Ruby,它将更接近:
<% @protocol.attachs.each do |attach| %>
<%= link_to "Download", attach.url(:original) %>
啊,愚蠢的错误!非常感谢你的帮助!
<p>
<b>Modification:</b>
<% for attach in @protocol.attachs %>
<%= link_to "Download", @protocol.attachs.url(:original)%>
<% end %>
</p>
<% @protocol.attachs.each do |attach| %>
<%= link_to "Download", attach.url(:original) %>