Paperclip::AdapterRegistry::NoHandlerError, Using fields_for and partial

1.1k views Asked by At

currently image is only returning a String. I learned that this is what is causing the error from this question: Paperclip exception : Paperclip::AdapterRegistry::NoHandlerError

Here are the current parameters that I'm seeing: Parameters:

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"SlvvynUVZCqV4fC3L8Dp1UM9IhDeihko44CFVyamxMU=",
 "examples"=>{"66"=>{"image"=>"Ambition flyer 2 (1).jpg",
 "description"=>"THis is a photo and what not"},
 "67"=>{"description"=>""}},
 "commit"=>"Submit",
 "collection_id"=>"19"}

How do I get :image to return something like this in params (from other post):

"asset"=>
  {"image"=>
    #<ActionDispatch::Http::UploadedFile:0x000000056679e8
    @content_type="image/jpg",
    @headers= "Content-Disposition: form-data; name=\"asset[image]\";
      filename=\"2009-11-29-133527.jpg\"\r\nContent-Type: image/jpg\r\n",
    @original_filename=""2009-11-29-133527.jpg"",
    @tempfile=#<File:/tmp/RackMultipart20120619-1043-yvc9ox>>}

**Currently, I have this in **edit_individual.html.erb****

<h2>Editing <%= @collection.title %> Collection</h2>
<%= form_tag update_individual_collection_examples_path, :method => :put do %>
  <% for example in @examples %>
    <%= fields_for "examples[]", example do |f| %>
      <h2></h2>
      <%= render 'pic-upload', :html => { multipart: true }, :f => f, :example => example %>
    <% end %>
  <% end %>
  <p><%= submit_tag "Submit" %></p>
<% end %>

and this in my _pic-upload.html.erb partial:

<table>
    <tr><td><%= image_tag example.image.url, size: "300x300" %></td>
        <td><%= f.label :image, "Upload picture" %></td>
        <td><%= f.file_field :image %></td>
        <td><%= f.label :description, "Description (Optional)" %></td>
        <td><%= f.text_area(:description, size: "50x3") %></td>
    </tr>
</table>

<% end %>

Solution Add :multipart => true the respective form_tag:

<%= form_tag(update_individual_collection_examples_path, :method => :put, :multipart => true) 

Syntax is important here. The form_tag must include (parenthesis around the methods).

Resource http://www.saalonmuyo.com/2010/01/27/using-form_tag-in-ruby-on-rails/

0

There are 0 answers