Skip to content

Commit

Permalink
Don't assume ActionMailer is available (#608)
Browse files Browse the repository at this point in the history
If the Rails app that uses this gem doesn't include the
ActionMailer railtie, the gem raises this error:

`uninitialized constant ReactOnRailsHelper::ActionMailer`

This change introduces a check that the ActionMailer
constant is defined before setting the 'inMailer' option.

I'm not quite sure how to test this, so if anyone has
ideas, that would be helpful.
  • Loading branch information
tuzz authored and justin808 committed Nov 30, 2016
1 parent ae9785b commit 2a227d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def initialize_redux_stores
def rails_context(server_side:)
@rails_context ||= begin
result = {
inMailer: controller.present? && controller.is_a?(ActionMailer::Base),
inMailer: in_mailer?,
# Locale settings
i18nLocale: I18n.locale,
i18nDefaultLocale: I18n.default_locale
Expand Down Expand Up @@ -400,4 +400,11 @@ def send_tag_method(tag_method_name, args)
options = args.delete_if { |key, _value| %i(hot static).include?(key) }
send(tag_method_name, *assets, options) unless assets.empty?
end

def in_mailer?
return false unless controller.present?
return false unless defined?(ActionMailer::Base)

controller.is_a?(ActionMailer::Base)
end
end

0 comments on commit 2a227d4

Please sign in to comment.