Reputation: 617
Here is my action do_registration in UserController
def do_registration
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.welcome_email(@user).deliver
format.html { render action: "do_registration" }
else
format.html { render action: "registration" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
I want to use a UserObserver instead to call the ActionMailer in the action so i writed in observers/user_observer.rb theese line of codes:
class UserObserver < ActiveRecord::Observer
observe User
def after_save(user)
UserMailer.welcome_email(@user).deliver
end
end
i added
config.active_record.observers = :user_observer
in my environment.rb, but when i register new user no mail is sent.
What is the problem?
Upvotes: 0
Views: 92
Reputation: 5213
you don't have to write this line observe User
in observer as you created this with model name only it will by default observe User class. But if you want to mention it explicitly it should be like this observe :user
.
Upvotes: 1