2

I'm trying to implement multiple file uploads with the Refile gem.

The user has to be able to upload multiple documents to a tournament model.

In the show template, I try to read out all uploaded documents like this:

<% @tournament.documents.each do |doc| %>                                                                                     
  <%= link_to @tournament.document_filename, attachment_url(doc, :file) %>
<% end %>

But this gives me a really long link in the view, something like this:

    /attachments/c569801bbd2a2ca51350ca326ec57e18d0d318e9/store/ad644cadeda8ee5197bc2bb8a66cc966f5b4b74fad7bbccd2ab798a10c98/file

Is there a way to output the filename of the uploaded documents?

Thanks a lot for your help,

Anthony

Toontje
  • 1,415
  • 4
  • 25
  • 43
  • 1
    By default the file name at the end of the link will just be the name of the attachment field, so in this case file. However this can be named to be anything you want. The attachment_url accepts the filename and format parameters: `Refile.attachment_url(doc, :file, filename: @tournament.document_filename, format: 'docx')` The file is stored under ad64ca... so it doesn't matter what you name it. Also check out https://github.com/refile/refile#additional-metadata for information on saving the meta-data – Adam Cooper Apr 05 '16 at 07:30
  • hi Adam, thanks for the information – Toontje Apr 06 '16 at 09:10

1 Answers1

0

A much simpler solution would be to store filename while creating a record. add these columns(filename, size, content_type)to your model and Refile will try to fill them automatically at the time of creation.

class StoreMetadata < ActiveRecord::Migration
  def change
    add_column :users, :profile_image_filename, :string
    add_column :users, :profile_image_size, :integer
    add_column :users, :profile_image_content_type, :string
  end
end
Abhinay
  • 1,796
  • 4
  • 28
  • 52