Nested form using paperclip

前端 未结 1 421
粉色の甜心
粉色の甜心 2021-01-01 04:00

I have a model called posts, and it has many attachments.

The attachments model is using paperclip.

I made a standalone model for creating attachments which

相关标签:
1条回答
  • 2021-01-01 04:07

    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).

    0 讨论(0)
提交回复
热议问题