Giter Club home page Giter Club logo

maily's Introduction

GitHub

Maily is a Rails Engine to manage, test and navigate through all your email templates of your app, being able to preview them directly in your browser.

Maily automatically picks up all your emails and make them accessible from a kind of dashboard.

Features:

  • Mountable engine
  • Visual preview in the browser (attachments as well)
  • Template edition (only in development)
  • Email delivery
  • Easy way (aka Hooks) to define and customize data for emails
  • Email versions
  • Flexible authorization system
  • Minimalistic and clean interface
  • Generator to handle a comfortable installation

Installation

Add this line to your Gemfile and then run bundle install:

gem 'maily'

Run generator:

> rails g maily:install

This generator runs some tasks for you:

  • Mounts the engine (to /maily by default) in your routes
  • Adds an initializer (into config/initializers/maily.rb) to customize some settings
  • Adds a file (into lib/maily_hooks.rb) to define hooks

Initialization and configuration

You should use the setup method to configure and customize Maily settings:

# config/initializers/maily.rb

Maily.setup do |config|
 # On/off engine
 # config.enabled = !Rails.env.production?

 # Allow templates edition
 # config.allow_edition = !Rails.env.production?

 # Allow deliveries
 # config.allow_delivery = !Rails.env.production?

 # Your application available_locales (or I18n.available_locales) by default
 # config.available_locales = [:en, :es, :pt, :fr]

 # Run maily under different controller ('ActionController::Base' by default)
 # config.base_controller = '::AdminController'

 # Configure hooks path
 # config.hooks_path = 'lib/maily_hooks.rb'

 # Http basic authentication (nil by default)
 # config.http_authorization = { username: 'admin', password: 'secret' }

 # Customize welcome message
 # config.welcome_message = "Welcome to our email testing platform. If you have any problem, please contact support team at [email protected]."
end

You can use the following format too:

Maily.enabled = ENV['MAILY_ENABLED']
Maily.allow_edition = false

Templates edition (allow_edition option)

This feature was designed for the development environment. Since it's based on just a file edition, and while running in production mode, code is not reloaded between requests, Rails doesn't take into account your changes (without restarting the server). Actually, allowing arbitrary Ruby code evaluation is potentially dangerous, and that's not a good idea in production.

So, template edition is not allowed outside of the development environment.

Hooks

Most of emails need to populate some data to consume it and do interesting things. Hooks are used to define this data via a little DSL. Hooks also accept "callable" objects to lazy load variables/data, so each email will evaluate its hooks on demand. Example:

# lib/maily_hooks.rb

user = User.new(email: '[email protected]')
lazy_user = -> { User.with_comments.first } # callable object, lazy evaluation
comment = Struct.new(:body).new('Lorem ipsum') # stub way
service = FactoryGirl.create(:service) # using fixtures with FactoryGirl

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:welcome, user, template_path: 'users')
  mailer.register_hook(:new_comment, lazy_user, comment)
end

Maily.hooks_for('PaymentNotifier') do |mailer|
  mailer.register_hook(:invoice, user, service)
end

Note that you are able to override the template_path and the template_name like can be done in Rails. You must pass these options as a hash and last argument:

Maily.hooks_for('YourMailerClass') do |mailer|
  mailer.register_hook(:a_random_email, template_path: 'notifications')
  mailer.register_hook(:another_email, template_name: 'email_base')
end

Email versions

You can add versions for special emails. This is useful in some cases where template content depends on the parameters you provide, for instance, a welcome message for trial accounts and gold accounts.

free_trial_account = -> { Account.free_trial.first }
gold_account = -> { Account.gold.first }

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:welcome, free_trial_account, version: 'Free trial account')
  mailer.register_hook(:welcome, gold_account, version: 'Gold account')
end

Email description

You can add a description to any email and it will be displayed along with its preview. This is useful in some cases like: someone from another team, for example, a marketing specialist, visiting Maily to review some texts and images; they can easily understand when this email is sent by the system.

Maily.hooks_for('BookingNotifier') do |mailer|
  mailer.register_hook(:accepted, description: "This email is sent when a reservation has been accepted by the system." )
end

Hide emails

You are also able to hide emails:

Maily.hooks_for('Notifier') do |mailer|
  mailer.hide_email(:sensible_email, :secret_email)
end

Use params

Support for ActionMailer::Parameterized is possible via with_params hash:

message = -> { 'Hello!' }

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:new_message, with_params: { message: message })
end

External emails

If you want to register and display in the UI, emails from external sources, like for example a gem, you can do it by adding a hook. Example:

Maily.hooks_for('Devise::Mailer') do |mailer|
  mailer.hide_email(:unlock_instructions)

  mailer.register_hook(:reset_password_instructions, user, 'random_token')
  mailer.register_hook(:confirmation_instructions, user, 'random_token')
  mailer.register_hook(:password_change, user)
end

Authorization

Basically, you have 2 ways to restrict access to the Maily section. You can even combine both.

Custom base controller

By default Maily runs under ActionController::Base, but you are able to customize that parent controller (Maily.base_controller option) in order to achieve (using, for example, before_action blocks) a kind of access control system. For example, set a different base controller:

Maily.base_controller = '::SuperAdminController'

And then write your own authorization rules in this defined controller:

class SuperAdminController < ActionController::Base
  before_action :maily_authorized?

  private

  def maily_authorized?
    current_user.admin? || raise("You don't have access to this section!")
  end
end

HTTP basic authentication

You can also authorize yours users via HTTP basic authentication, simply use this option:

Maily.http_authorization = { username: 'admin', password: 'secret' }

Notes

Rails 4.1 introduced a built-in mechanism to preview the application emails. It is in fact, a port of basecamp/mail_view gem to the core.

Alternatively, there are more gems out there to get a similar functionality, but with different approaches and features. Like for example: ryanb/letter_opener, sj26/mailcatcher or glebm/rails_email_preview.

Development

Any kind of feedback, bug report, idea or enhancement are really appreciated ๐ŸŽ‰

To contribute, just fork the repo, hack on it and send a pull request. Don't forget to add tests for behaviour changes and run the test suite:

> bundle exec rspec

Run the test suite against all supported versions:

> bundle exec appraisal install
> bundle exec appraisal rspec

Run specs against specific version:

> bundle exec appraisal rails-6.0 rspec

Demo

Start a sample Rails app (source code) with Maily integrated:

> bundle exec rake web # PORT=4000 (default: 3000)

License

Copyright (c) Marc Anguera. Maily is released under the MIT License.

maily's People

Contributors

alexlarra avatar araluce avatar arturminnullin avatar barrywoolgar avatar cenxky avatar djfpaagman avatar gnatok avatar krismichalski avatar markets avatar mtvillwock avatar seanhussey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maily's Issues

Engine doesn't render

Not sure what I'm doing wrong.

NoMethodError in Maily::Emails#index

---

Showing /Users/kristiangerardsson/www/example.com/app/views/application/_account_popup_menu.html.erb where line #1 raised:

undefined method `employee_path' for #<#<Class:0x007f9a37a04cf8>:0x007f9a38076438>

---

app/views/application/_account_popup_menu.html.erb:1:in `_app_views_application__account_popup_menu_html_erb___2286500346444814438_70150160003460'
app/views/application/_app_bar.html.erb:6:in `_app_views_application__app_bar_html_erb__2941068856054159746_70150140576160'
app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___763355335627937910_70150166256700'

Seems it tried to render the apps normal layout. Just browsing localhost:3000/maily

I just used the generator to install the config and hooks file, and haven't changed them.

Any ideas?

Remove sass and move to plain css

In the recents Rails releases they introduced a new pipeline via webpacker and some teams moved not only the js to webpack, but also their css too. Other people are using the Rails API mode, which doesn't include the sprockets railtie neither.

In summary, relying on the original "assets pipeline" and sass is harder nowadays, so would be nice to move our css out of sprockets and sass, and use just plain css3. Also, apps with node-sass or postcss (via webpacker) wont need to install sassc-rails (which contains native deps too).

Evidences: #46, #22

Email content rendered always as text

Suddenly emails content is only rendered as text. Any idea why this could be?

maily - account mailer email changed 2018-12-19 07-34-05

Also, is there anyway to update the emails without having to restart the rails server?

TIA!

error | rails g maily:install

/home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/maily-0.10.1/app/controllers/maily/application_controller.rb:2:in <module:Maily>': undefined method constantize' for nil:NilClass (NoMethodError)
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/maily-0.10.1/app/controllers/maily/application_controller.rb:1:in <main>' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in load'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in load' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:476:in block in load_file'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:661:in new_constants_in' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:475:in load_file'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:373:in block in require_or_load' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:37:in block in load_interlock'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:14:in block in loading' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:151:in exclusive'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:13:in loading' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:37:in load_interlock'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:356:in require_or_load' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:48:in block in require_or_load'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in allow_bootsnap_retry' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:47:in require_or_load'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:334:in depend_on' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:85:in depend_on'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:246:in require_dependency' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:478:in block (2 levels) in eager_load!'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:477:in each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:477:in block in eager_load!'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:475:in each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:475:in eager_load!'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:356:in eager_load!' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application/finisher.rb:69:in each'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application/finisher.rb:69:in block in <module:Finisher>' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in instance_exec'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in run' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in block in run_initializers'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in block in tsort_each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in each_strongly_connected_component_from' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in block in each_strongly_connected_component'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in call'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in each_strongly_connected_component' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in tsort_each'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in tsort_each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in run_initializers'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:361:in initialize!' from /home/rafarosa92/Documentos/osmarapp/config/environment.rb:5:in

'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in block in require_with_bootsnap_lfi'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in register' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in require_with_bootsnap_lfi'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in block in require'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in load_dependency' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in require'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:106:in preload' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:157:in serve'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:145:in block in run' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in loop'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in run' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in <top (required)>'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require'
from -e:1:in `'

Allow to add multiple hooks/versions per mail

Possible APIs:

a) use register_hook multiple times, pass version name as a param:

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hook(:welcome, free_trial, version: "Free trial account")
  mailer.register_hook(:welcome, client, version: "Client account")
end

b.1) new method register_hooks (plural) with a different signature (passing hash):

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hooks(:welcome, versions: {
    "Free trial account": free_trial
    "Client account": client
  })
end

b.2) new method register_hooks (plural) with a different signature (passing array):

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hooks(:welcome, [
    ["Free trial account", free_trial],
    ["Client account", client]
  ])
end

c) new method register_version:

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hook(:welcome, free_trial)
        .register_version("Client account", client)
end

App fails to boot because Maily expects the asset pipeline to be present

I don't know if this constitutes a bug, but my Rails 6 app is webpacker-only and after installing the gem it is not possible to enter the rails console (or run the generator). Consider this a half bug report, half workaround guide for anyone who needs it.

The bug part is because lib/maily/engine.rb attempts to modify config.assets.precompile, which does not exist without the asset pipeline and therefore raises an undefined method 'assets' for #<Rails::Engine::Configuration ...> error.

If I wrap that section in a config.respond_to?(:assets) then everything works, except the assets, as you would expect. I've just copied the SCSS out into a new pack file, and overridden the maily/application layout file in my app. Now everything except the images work, and I'm fine with that.

I'm not sure what the proper solution is. The first thing that comes to mind is maybe include a static version of the compiled assets in the gem and update the templates to source them out of /public using something like:

module Maily
  class Engine < ::Rails::Engine
    ...
    config.app_middleware.use(
      Rack::Static,
      urls: ["/maily-assets"], root: "maily/public"
    )
  end
end

Happy to do a PR with the respond_to? bit in, but that seems like only half the job.

Thanks

Edit mail fails with slim as a template engine

Description

Currently when you try to edit an email on an application using slim as a template engine you get the following error:

Errno::ENOENT in Maily::EmailsController#edit
No such file or directory @ rb_sysopen - /../email.text.erb

Lazy load hooks

Make hooks to load data only when using the engine (first hit to /maily), to avoid boot time penalty.

Breaks if sass-rails is not present

Description

On an application i have, we are mainly not using the asset pipeline and we use the webpacker gem instead. (webpack)
So that's why we don't have sass-rails on our Gemfile.

Adding the gem fixes the issue but maybe this gem should require it?

Configured available locales not being picked up by maily

Description

With the following configuration options:

# config/application.rb
config.i18n.available_locales = %i[en nl]
config.i18n.default_locale = :nl

I get this:

maily - caregiver mailer new job offer notification 2018-06-23 11-40-47

Explicitly setting:

config.available_locales = I18n.available_locales

on config/initializers/maily.rb also doesn't fix the issue because at that point I18n.available_locales has all the locales.

Inherited methods dont show on ui

Give the following mailer and hooks:

# app/mailers/user_mailer.rb

class UserMailer < Devise::Mailer
  private

  # headers for devise mailers
  def headers_for(action, opts)
    super action, opts.merge(template_path: "/mailers/user_mailer")
  end
end
# lib/maily_hooks.rb

user = User.first
token = "token"

Maily.hooks_for("UserMailer") do |mailer|
  mailer.register_hook(:reset_password_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:confirmation_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:invitation_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:unlock_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:password_change, user, template_path: "mailers/user_mailer")
  mailer.register_hook(:email_changed, user, template_path: "mailers/user_mailer")
end

On the ui i get this: (text version for simplicity)

User mailer (0)

Exception when running the install generator

Description

When running bin/rails g maily:install

I get the following error (at the bottom of the error trace, let me know if you want the full trace)

lib/generators/maily/install_generator.rb:30:in `block in build_hooks': undefined method `name' for #<Array:0x00007fd52dd60f38> (NoMethodError)

Arrays in arguments of mailer.register_hook is not supported

Hi @markets,

Thanks for your Maily gem, it lets us easier to preview and test Emails. During working with it, I found mailer.register_hook doesn't support Array type arguments.

class Notifier < ActionMailer::Base
  def test_mail(to_mails, cc_mails)
     mail to: to_mails,  cc: cc_mails, subject: "Test"
  end
end

to_mails = %w([email protected] [email protected])
cc_mails = %w([email protected] [email protected])

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:test_mail, to_mails, cc_mails)
end

The codes above will raise an error while running:

test_mail email requires at the most 2 arguments, passed 4

So I made a PR to fix it, pls have a look!

Merci!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.