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:
- Put a
begin/rescue around the call to params.
- 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
We have the following mailer helper:
and we call
test_enabled?from a mailer view. This ends up raising an error:The problem is this line in Split::EncapsulatedHelper:
Due to a Rails bug (rails/rails#15613),
defined?(params)returns true even though the method is not defined. The view delegatesparams, 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:
begin/rescuearound the call toparams.paramsat all; if there's aparamsmethod defined, then you're probably in a controller anyway, so you could just useSplit::Helper.Thoughts?
Thanks!
Tony