2

当前图像仅返回一个字符串。我了解到这是导致此问题错误的原因:Paperclip exception : Paperclip::AdapterRegistry::NoHandlerError

以下是我看到的当前参数: 参数:

{"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"}

我如何才能:image在参数中返回这样的东西(来自其他帖子):

"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>>}

**目前,我在 **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 %>

这在我的_pic-upload.html.erb部分:

<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 %>

解决方案 添加:multipart => true相应的form_tag

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

语法在这里很重要。form_tag 必须包含(方法周围的括号)。

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

4

0 回答 0