I have a Reminder model, Attachment Model and it has habtm relationship
with each other.
So I have a created another table as attachment_reminders table in mysql
through migrations and it has reminder_id and attachment_id fields.
In controller I need to copy a record in attachment table and save it in
Attachment table. I am able to do that..
But I need to add the same in the attachment_reminders table also. How
can I achieve it. Please find my code below
def view_reminder
@reminder = Reminder.find(params[:id2])
@attachments = @reminder.attachments
if request.post?
Reminder.create(:sender=>@reminder.user_id,:recipient=>params[:recipient],:body=>params[:body])
@attachments.each do |at|
rec = at.clone
rec.created_at = Time.now
rec.updated_at = Time.now
rec.save
end
flash[:notice]="Reminder updated successfully"
redirect_to :controller=>"reminde", :action=>"view_reminder",
:id2=>params[:id2]
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/645a8b26e1047e03d337b661a43f4c20%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment