Nested form using paperclip

强颜欢笑 提交于 2019-11-30 09:55:59

You are missing the :multipart option in your form definition:

<% @attachment = @post.attachments.build %>
<%= form_for @post, :html => { :multipart => true } do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :description %><br />
    <%= f.text_area :description %>
  </div>
  <div class="field">
    <%= f.fields_for :attachments, @attachment do |at_form| %>

      <%= at_form.file_field :pclip %>

    <% end %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Also, your @posts variable should really be @post (single ActiveRecord instance as opposed to an array of ActiveRecord instances).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!