Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally use helper_method in Flash concern #33569

Merged
merged 1 commit into from
Sep 13, 2018
Merged

Conditionally use helper_method in Flash concern #33569

merged 1 commit into from
Sep 13, 2018

Conversation

eric-hemasystems
Copy link
Contributor

I was attempting to use the flash functionality in a Metal controller. When including the flash concern I received the following error:

NoMethodError: undefined method `helper_method'....

Either:

  • AbstractController::Helpers should be a dependency of ActionController::Flash
  • ActionController::Flash should not require the existence of AbstractController::Helpers.

Since my use case (set a flash and redirect) has no need for the helper method and that is a common use case, making the dependency conditional seemed the better option.

NOTE: This is similar to issue #21067 only the error is within Rails itself while that issue had the error within Devise.

I was attempting to use the `flash` functionality in a `Metal`
controller. When including the `flash` concern I received the following
error:

    NoMethodError: undefined method `helper_method'....

Either:

- `AbstractController::Helpers` should be a dependency of
  `ActionController::Flash`
- `ActionController::Flash` should not require the existence of
  `AbstractController::Helpers`.

Since my use case (set a flash and redirect) has no need for the helper
method and that is a common use case, making the dependency conditional
seemed the better option.

NOTE: This is similar to issue #21067 only the error is within Rails
itself while that issue had the error within Devise.
@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kamipo (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@eric-hemasystems
Copy link
Contributor Author

CI failures seem unrelated to this PR.

@rafaelfranca rafaelfranca merged commit 19cb7a9 into rails:master Sep 13, 2018
@eric-hemasystems eric-hemasystems deleted the conditional-flash-helper branch September 13, 2018 20:21
end
helper_method type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can execute

define_method(type) do
  request.flash[type]
end

unless #helper_method defined,

so probably fix should be like:

helper_method type if respond_to? :helper_method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it makes sence, I'll send a patch to fix that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed there is no reason for the method other than to provide as a helper method so put the conditional around both the definition and exposure of that definition. But if people use that method from within a controller then sure, seems you could do what you suggest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was fixed in 7265b89.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants