Closed denwwer closed 10 years ago
Rails 4 class MailerForm has_many Recipient and accepts_nested_attributes_for :recipients
example:
form = MailerForm.new(some_recipients_data) p form.recipients >> [#<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">, # <MailerForm::Recipient mailer_form_id: nil, email: "mail1@example.com">] form.recipients.where(:email => "mail1@example.com").delete_all p form.recipients # got this >> [#<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">, # <MailerForm::Recipient mailer_form_id: nil, email: "mail1@example.com">] # instead of >> [ #<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">]
so how I can do destroy ?
fixed using next solution
form.recipients = form.recipients.to_a.reject!{|it| it.email == 'mail1@example.com'} p form.recipients >> [ #<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">]
Rails 4 class MailerForm has_many Recipient and accepts_nested_attributes_for :recipients
example:
so how I can do destroy ?