Reputation: 1712
I would like to send an email to a user once the status of their pdform is updated. I already have some stuff written out on how I want this done.
In my pdform.rb
model
after_update :sendemail
def sendemail
if status_changed?
end
end
I already have emails being sent out when the user creates a new form, however, I am not sure how to send an email in the model.
The controller has this mailer function that works correctly. How could I send this in this model?
NewPdform.notify_user(current_user, @pdform).deliver
Any help would be greatly appreciated. Still getting the hang of ActiveRecord.
In my pdforms_controller update method I have added the following variable.
update_user = @pdform.user
I added an attr_accessor in pdform.rb
(the model)
attr_accessor :update_user
after_update :sendemail
def sendemail
NewPdform.notify_update(update_user).deliver
end
And in my mailer
def notify_update(user)
@user = user
mail(to: @user.email, subject: "some change occured")
end
Upvotes: 0
Views: 855
Reputation: 1712
I solved my own issue after using my brain more extensively.
In the call to the mailer function instead of passing the parameter of pdform
, which is the name of the class anyways, just pass self
.
def sendemail
NewPdform.notify_update(self).deliver
end
Upvotes: 1