Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So there are a few issues here.</p> <p>First, Paperclip's <code>has_attached_file</code> method isn't an association to many files. It looks like you're trying to build an "asset" as if it's a Rails association. All Paperclip does is put a couple of fields into your table to store some meta-data about the file and you get one attached file per declaration of <code>has_attached_file</code>. If you want to attach 5 files, you would need to do something like:</p> <pre><code>has_attached_file :asset1 has_attached_file :asset2 has_attached_file :asset3 has_attached_file :asset4 has_attached_file :asset5 </code></pre> <p>OR, alternatively, you could create another model just to store the files. For example:</p> <pre><code>class Listing &lt; ActiveRecord::Base has_many :assets end class Asset &lt; ActiveRecord::Base belongs_to :listing has_attached_file :picture end </code></pre> <p>That way, you could have multiple assets attached to one listing (you didn't say what the original object was so I just called it "listing").</p> <p>Second, there is no such thing as a multiple file upload in HTML (and, as such, the <code>file_field</code> method doesn't take a <code>:multiple =&gt; true</code> argument. You'll have to use something beyond Rails built-in form handling if you want multiple-file upload. Uploadify is a decent choice (that I've used before). There is a gem that will transform file fields to use uploadify (and will support the <code>:multiple =&gt; true</code> syntax that you want): <a href="https://github.com/mateomurphy/uploadify_rails3/wiki" rel="noreferrer">https://github.com/mateomurphy/uploadify_rails3/wiki</a>. However, I cannot vouch for how good it is.</p> <p>My advice would be to start step-by-step. Uploading via Flash to Rails can be a complicated process that involves dealing with the CSRF meta-tag and other fields in your form. Start by making a form that allows a user to upload one file and stores it through Paperclip. Then maybe break the <code>has_attached_file</code> declaration into another model so that you can have 1 or many files associated with a model (as shown in the multi-model code block above). Then try adding Uploadify or another alternative. Ernie Miller has a decent tutorial on integrating Uploadify: <a href="http://erniemiller.org/2010/07/09/uploadify-and-rails-3/" rel="noreferrer">http://erniemiller.org/2010/07/09/uploadify-and-rails-3/</a>.</p> <p>To start, remember that <code>has_attached_file</code> can only attach <em>one</em> file. When you try calling <code>@listing.assets</code> there is no "assets". There is <em>an</em> asset. You need to create a separate model yourself and use Rails' associations if you want multiple files.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload