Forum: Ruby on Rails Paperclip with nested form saving null values in db

Ecec81af7caddc8730eee285475df4da?d=identicon&s=25 ruby rails (rubyonrails)
on 2013-10-04 11:53
I have a Attachment model and Reminder model. The Reminder has many
attachments and Attachment belongs to a Reminder. I have set up the
association and it works fine. I have defined
accepts_nested_attributes_for :attachments in the Reminder model also.
I have a nested form where there is multiple file upload fields. I am
using  paperclip for saving file attachments. I have set up multipart
true to the form. But when I submit the form the Reminder model creates
an entry in db with Delayed Jobs but in the Attachment model null values
are getting saved in the db. Please find the part of my code below. Any
inputs /suggestions would be great..

    <% 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 id="submit-button">
            <%=submit_tag "#{t('send')}", :class => 'button',
:disable_with => "#{t('please_wait')}" %>
      <% end %>
=====Controller code...

    def create_reminder
          @recipients ={|a|
          unless params[:reminder][:body] == "" or params[:recipients]
== ""
            recipients_array = params[:recipients].split(",").reject{|a|
a.strip.blank?}.collect{ |s| s.to_i }
            Delayed::Job.enqueue(  =>,:recipient_ids =>
   "Before saving
   "After Saving

            flash[:notice] = "Message Sent Sucessfully"
            redirect_to :controller=>"reminder_plugin",
            flash[:notice]="Please fill the required fields"
            redirect_to :controller=>"reminder_plugin",
        rescue Exception=> e
          puts "Inside create action.........",e.backtrace
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.