Skip to content

Commit 2a227d4

Browse files
tuzzjustin808
authored andcommitted
Don't assume ActionMailer is available (#608)
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.
1 parent ae9785b commit 2a227d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/helpers/react_on_rails_helper.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def initialize_redux_stores
345345
def rails_context(server_side:)
346346
@rails_context ||= begin
347347
result = {
348-
inMailer: controller.present? && controller.is_a?(ActionMailer::Base),
348+
inMailer: in_mailer?,
349349
# Locale settings
350350
i18nLocale: I18n.locale,
351351
i18nDefaultLocale: I18n.default_locale
@@ -400,4 +400,11 @@ def send_tag_method(tag_method_name, args)
400400
options = args.delete_if { |key, _value| %i(hot static).include?(key) }
401401
send(tag_method_name, *assets, options) unless assets.empty?
402402
end
403+
404+
def in_mailer?
405+
return false unless controller.present?
406+
return false unless defined?(ActionMailer::Base)
407+
408+
controller.is_a?(ActionMailer::Base)
409+
end
403410
end

0 commit comments

Comments
 (0)