<% if form_file.file.blank? && form_file["file"].blank? %>
<%= t(:no_file) %>
<% else %>
<% belongs_to_record = form_file.relations.select{|k,v| v.macro == :belongs_to}.first[0] rescue nil %>
<% url = form_file.file.url %>
<% if belongs_to_record.present? && (form_file.send(belongs_to_record).copy_id.present? rescue false) %>
<% begin
belongs_to_record = belongs_to_record.classify.constantize.find(form_file.send(belongs_to_record).copy_id)
target_form_files = belongs_to_record.send(form_file.class.to_s.underscore+"s")
target_form_file = target_form_files.select{|ff| ff["file"] == form_file["file"]}.first
url = target_form_file.file.url
rescue
nil
end %>
<% end %>
<%= link_to content_tag(:i) + form_file.file_identifier, url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %>
<% end %>
<% end %>