在 ActiveAdmin 中选中或取消选中“批准”后发送电子邮件通知用户

Send email after checked or unchecked " approved" in ActiveAdmin to notify the user

我想在用户批准或不批准时通知他。

admin/user.rb我有

ActiveAdmin.register User do

  permit_params :email, :name, :firstname, :mailsent, :email_confirmed, 
 :adminuser, :approved

 index do
  column :email
  column :name
  column :firstname
  column :mailsent
  column :email_confirmed
  column :adminuser
  column :approved
 actions
 end

end

您可以覆盖更新方法。确保只有在没有阻止更新的错误时才发送电子邮件,并且(当然)只有在批准的列发生更改时才发送电子邮件。

controller do
  def update
    @approved = User.find(params[:id]).try(:approved)
    super
    if @user.valid? && @user.approved != @approved
      # send email here
    end
  end
end