-
-
Save ismailmechbal/b2200f118b2934aabab0 to your computer and use it in GitHub Desktop.
Send batch emails on ActiveAdmin Rails 4.2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Contact batch email --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> | |
</head> | |
<body> | |
<div>Name: <%= @name %></div> | |
<br> | |
<div>Subject: <%= @subject %></div> | |
<br> | |
<div>Reply to: <%= @email %></div> | |
<br> | |
<div>Message: </div> | |
<br> | |
<div><p><%= @message %></p></div> | |
<br> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContactBatchMailer < ActionMailer::Base | |
default from: "[email protected]" | |
def contact_batch_email(name, email, message, subject, recipient) | |
@message = message | |
@name = name | |
@email = email | |
@subject = subject | |
@recipient = recipient | |
mail(to: recipient, :reply_to => email, name: @name, subject: @subject) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
batch_action :email, form: {subject: :text, message: :textarea}, confirm: "Please enter the subject and the message below", if: proc{ your_condition_here_to_make_this_resource_available } do |ids, inputs| | |
batch_action_collection.find(ids).each do |user| | |
ContactBatchMailer.contact_batch_email(user.first_name, '[email protected]', inputs[:message], inputs[:subject], user.email).deliver | |
end | |
redirect_to collection_path, notice: "The batch email has been sent to all the users you selected." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment