简体   繁体   English

回形针显示多个文件上传

[英]Paperclip displaying multiple file uploads

I have multiple files being uploaded using Paperclip, but I am having trouble displaying them. 我有多个文件正在使用回形针上载,但是我无法显示它们。 Here is what I'm trying: 这是我正在尝试的:

Model(s): 楷模):

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

Part of my controller: 我的控制器的一部分:

  def new
    @protocol = Protocol.new
    @protocol.attachs.build

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @protocol }
    end
  end

Part of my form where I store images: 我在其中存储图像的表单的一部分:

  <div class="field"> 
    <%= f.label :file, "Mod" %>
    <%= file_field_tag('protocol_attachs_attributes_file', multiple: true, name: "protocol[attachs_attributes][][file]") %> 
  </div>

And my show: 我的节目:

<p>
  <b>Modification:</b>
  <% for attach in @protocol.attachs %> 
    <%= link_to "Download", @protocol.attachs.url(:original)%>
  <% end %>
</p>

I'm getting the same file over and over, every time I upload (even if it's a different file). 每次上传时,我都会一遍又一遍地获得相同的文件(即使它是不同的文件)。 Can anyone assist me with this issue? 谁能协助我解决这个问题?

You're iterating, but running the same code for each attachment link. 您正在迭代,但是为每个附件链接运行相同的代码。

Using canonical Ruby, it would be closer to: 使用规范的Ruby,它将更接近:

<% @protocol.attachs.each do |attach|  %> 
  <%= link_to "Download", attach.url(:original) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM