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>
</div>
</div>
<div id="submit-button">
<%=submit_tag "#{t('send')}", :class => 'button',
:disable_with => "#{t('please_wait')}" %>
</div>
<% end %>
=====Controller code...
def create_reminder
if request.post?
@recipients =
User.active.find_all_by_id(recipients_array).sort_by{|a|
a.full_name.downcase}
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(DelayedReminderJob.new(:sender_id =>
@user.id,:recipient_ids =>
recipients_array,:subject=>params[:reminder][:subject],:body=>params[:reminder][:body]))
@reminder.message_addl_attachments.build
logger.info "Before saving
attachments....#{@reminder.message_addl_attachments.inspect}"
@reminder.message_addl_attachments.save
logger.info "After Saving
attachments....#{@reminder.message_addl_attachments.inspect}"
flash[:notice] = "Message Sent Sucessfully"
redirect_to :controller=>"reminder_plugin",
:action=>"create_reminder"
else
flash[:notice]="Please fill the required fields"
redirect_to :controller=>"reminder_plugin",
:action=>"create_reminder"
end
end
rescue Exception=> e
puts "Inside create action.........",e.backtrace
end
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cae25a850e13b42443a349e433c53297%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment