简体   繁体   English

回形针将空值保存在rails2.3中的db中

[英]paperclip saving null values in db in rails2.3

I am using nested fields in a form with fields_for..I need to add multiple attachments dynamically and submit the form. 我正在使用具有fields_for的表单中的嵌套字段。我需要动态添加多个附件并提交表单。 In the console I am getting params for attachment as 在控制台中,我得到附件的参数为

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

Iam not sure how to handle this in controller and save the attachment. 我不确定如何在控制器中处理此问题并保存附件。 I have built the associations properly. 我已经正确建立了关联。 In the controller I am doing like this. 在控制器中,我这样做。

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

Please find the full params in console. 请在控制台中找到完整的参数。

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]

But it is not saving it in my rails public directory... In the db it is saving null values also.. Please help. 但是它没有将其保存在我的rails公共目录中。在数据库中,它还保存了null值。

============== myview.html.erb ============== 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 %>

What your first have to check: 您首先要检查的是:

  1. Is ImageMagick installed and working 是否已安装ImageMagick并正常工作
  2. Does your form have the attribute "multipart=>true" 您的表单是否具有属性“ multipart => true”

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM