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:
<% @protocol.attachs.each do |attach| %>
<%= link_to "Download", attach.url(:original) %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.