Skip to content

Split::EncapsulatedHelper can't be used in mailer views #256

@afn

Description

@afn

We have the following mailer helper:

class MyMailerHelper
  include Split::EncapsulatedHelper
  def test_enabled?
    ab_test('my_test', 'disabled', 'enabled') == 'enabled'
  end
end

and we call test_enabled? from a mailer view. This ends up raising an error:

     ActionView::Template::Error:
       undefined method `params' for #<MyMailer:0x007ff87555bd18>

The problem is this line in Split::EncapsulatedHelper:

      _params = defined?(params) ? params : {}

Due to a Rails bug (rails/rails#15613), defined?(params) returns true even though the method is not defined. The view delegates params, along with other methods, to the controller (and in this case, the "controller" is a mailer, which doesn't define that method).

I think Rails is the right place to fix the bug, but it would probably still be worthwhile to work around the issue in Split. A couple of options for this:

  1. Put a begin/rescue around the call to params.
  2. Don't call params at all; if there's a params method defined, then you're probably in a controller anyway, so you could just use Split::Helper.

Thoughts?

Thanks!
Tony

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions