0

我在带有fields_for的表单中使用嵌套字段。我需要动态添加多个附件并提交表单。在控制台中,我正在获取附件参数

"reminder"=>{"message_addl_attachments_attributes"=>{"1380913359931"=>{"attachment"=>#<File:/tmp/RackMultipart20131005-4343-1cxemfz-0>}}

我不确定如何在控制器中处理此问题并保存附件。我已经正确地建立了关联。在控制器中,我正在这样做。

    def create_reminder
    @reminder = Reminder.new
    @addl = @reminder.message_addl_attachments.build(params[:reminder][:message_addl_attachments])
    @addl.save
end

请在控制台中找到完整的参数。

Processing ReminderPluginController#create_reminder (for 127.0.0.1 at 2013-10-05 00:53:33) [POST]
  Parameters: {"reminder"=>{"subject"=>"nkljkl", "body"=>"<p>jkljkljkl jlkj</p>", "email"=>"", "message_addl_attachments_attributes"=>{"1380914609923"=>{"attachment"=>#<File:/tmp/RackMultipart20131005-4488-1agtr7m-0>}}}, "controller"=>"reminder_plugin", "select_batch"=>{"batch"=>"2"}, "select_department"=>{"department"=>""}, "recipients"=>"20", "authenticity_token"=>"L0py7Xdsf7JSQGqn2bdoE7EXDVN9ZmNNSwl0dbHMkfM=", "action"=>"create_reminder", "commit"=>"Send"}
[paperclip] Saving attachments.
Redirected to http://localhost:3000/reminder/create_reminder
Completed in 459ms (DB: 217) | 302 Found [http://localhost/reminder_plugin/create_reminder]

但它没有将它保存在我的rails公共目录中......在数据库中它也在保存空值......请帮助。

============== myview.html.erb

<% form_for @reminder, :url => { :action => "create_reminder"
},:html=>{:multipart=>true} do |l| %>
                <div class="addl_attachments">
              <% l.fields_for :attachments do |a| %>
                  <%= render "message_addl_attachment_fields",:f=>a  %>
              <% end %>
              <div class="add_addl_attachment">
                <%= link_to_add_addl_attachment "#{image_tag
"buttons/add_2.png" } #{t('add_txt')}", l, :attachments %>
              </div>
              </div>
          </div>
          <div id="submit-button">
            <%=submit_tag "#{t('send')}", :class => 'button',
:disable_with => "#{t('please_wait')}" %>
          </div>
      <% end %>
4

1 回答 1

-1

您首先必须检查的内容:

  1. ImageMagick 是否已安装并正常工作
  2. 您的表单是否具有属性“multipart=>true”

希望这可以帮助 :)

于 2013-10-04T20:01:21.303 回答