I\'m fairly new to rails and trying to figure things out. I recently got a mailer all setup and it was working fine. But I am trying to add a second mailer for user actions
When users sign up with Devise, they don't go through the UsersController
.
You might want to add the mail sending code in the User
model.
For example, in app/models/user.rb
:
class User < ActiveRecord::Base
# ...
after_create :send_admin_mail
def send_admin_mail
UserMailer.send_new_user_message(self).deliver
end
# ...
end
This is done by utilizing the Active Record after_create
callback.
Confirmation emails should be sent from the controller. It's simple to override the Devise::RegistrationsController
defaults.
Create the file app/controllers/my_registrations_controller.rb
(name this whatever you want)
class MyRegistrationsController < Devise::RegistrationsController
def create
super
if @user.persisted?
UserMailer.new_registration(@user).deliver
end
end
end
Then in your routes:
devise_for :users, :controllers => { :registrations => "my_registrations" }