0.01
No commit activity in last 3 years
No release in over 3 years
Rails Bindings for Apostle
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.4
>= 0

Runtime

 Project Readme

Apostle Rails

Gem Version

Rails Bindings for Apostle.io

Installation

Add this line to your application's Gemfile:

gem 'apostle-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install apostle-rails

setup

First, generate the gem's initializer:

 rails generate apostle:install

This will create the following initializer:

 config/initializers/apostle.rb
 
 Apostle.configure do |config|
   config.domain_key = 'APOSTLE_DOMAIN_KEY'
 end

Usage

apostle-rails is designed to feel like the ActionMailer API as much as possible.

Changing an existing mailer is easy.

class MyMailer < ActionMailer::Base
	def my_mail name, email, message
		@message, @name = message, name
		mail to: email, subject: "Your message"
	end
end

becomes

class MyMailer < ActionMailer::Base
  include Apostle::Mailer
   
   def my_mail name, email, message
     @message, @name = message, name
	mail "my_mail", email: email
   end
 end

The first param passed to mail is the template slug, and instead of to, use email. Apostle::Mailer automatically adds any instance variables you set to the Apostle::Mail instance.

Instead of returning a Mail::Message object when you call MyMailer.my_mail you get an instance of Apostle::Mail, which you can then call deliver on.

  MyMailer.my_mail("Mal Curtis", "mal@mal.co.nz", "Hi there").deliver!

Instance variables

Any instance variables you assign will be converted to their JSON representation via #as_json. This can end up adding extra information which you may not want to send, so it might be easier to create your own hash representations of information.

def new_book book, email
  @book = { title: book.title, author: book.author.name }
  mail "new_book", email: email
end

Who

Created with ♥ by Mal Curtis (@snikchnz)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request