I have a User model (with Devise), and a Post model that belongs to the user. I used this railscast (pro) to send the User an email after creating an account
I created a “NewPostMailer”
This is my mailer:
class NewPostMailer < ActionMailer::Base
default :from => "email@gmail.com"
def new_post_email(user)
@user = user
@url = "http://localhost.com:3000/users/login"
mail(:to => user.email, :subject => "New Post")
end
end
My posts_controller:
def create
@post= Post.new(params[:post])
respond_to do |format|
if @deal.save
NewPostMailer.new_post_confirmation(@user).deliver
format.html { redirect_to @post, notice: 'Post was successfully created.' }
post.rb
after_create :send_new_post_email
private
def send_new_post_email
NewPostMailer.new_post_email(self).deliver
end
What do I have to change to send the User an email after he creates a Post. Thanks.
Create another mailer (http://railscasts.com/episodes/206-action-mailer-in-rails-3)
In your Post model
Sending an email is very slow so think about putting this in a background job.