Rails - Devise send user email after sign_up/create

后端 未结 2 1669
无人及你
无人及你 2020-12-23 20:29

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

2条回答
  •  自闭症患者
    2020-12-23 21:06

    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.

提交回复
热议问题