-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Include TagHelper but don't explicitly require it #3943
Conversation
Looks like the concern and sanitize helper requires are needed. Why capture and autoload? |
Awesome pull request. +1 |
@jeremy Without |
Okay, it should be ready to pull. I can squash these into a single commit, if you'd prefer. |
The /cc @josevalim |
We should support manual requires BUT in order for all manual requires to work in Rails, you MUST require the parent library. So be sure you required "action_view" first. In this case, you should probably require "action_view/helpers" as well. Those files are requiring shared AS dependencies and setting up autoload only. If a require is still missing after requiring those two files, a Pull Request is welcome. |
If we're requiring 'action_view' then that's all that is needed since everything is autoloaded, e.g: require 'action_view'
class MyClass
include ActionView::Helpers::TextHelper
def my_method
simple_format("Your text here")
end
end If this is the case we probably don't want explicit requires for other helpers within a helper as it may prevent proper autoloading if they get required before 'action_view/helpers' |
Exactly. It could even lead to double requires. |
Do I really need to require all of |
requiring "action_view" doesn't actually load anything from action view. it just sets up autoloads and requires common dependencies. https://github.com/rails/rails/blob/master/actionpack/lib/action_view.rb Yes, you need to do that. On all frameworks (active_model, action_controller, etc). |
I still get errors when I |
Yeah, so that's a bug. :) Reopened. |
@josevalim Okay, so what needs to be changed in this pull request before it can be merged? |
Don't In this case there is a bug for TextHelper - it uses the tag method so it should include TagHelper and not require it like it does at the moment. Also the SanitizeHelper requires the TagHelper but neither includes it or uses it. |
@pixeltrix If I've interpreted what you've said correctly, my pull request now implements your suggestion. However, this does not fix my original problem:
|
@jeremy @josevalim @pixeltrix I've given you all commit access to my fork of the rails repo, in case you want to push to the |
I think what @pixeltrix meant was that you don't need to require the text_helper explicitly since it'll auto-load when you require action_view:
|
@sferik don't require, use include: >> require 'action_view'
=> true
>> include ActionView::Helpers::TagHelper
=> Object
>> include ActionView::Helpers::TextHelper
=> Object
>> simple_format("Hello World")
=> "<p>Hello World</p>" |
Gotcha. Is this badboy ready to merge or should we cleanup all the explicit requires of Action View helpers? |
It is fine to merge imho, but could you please squash? <3 |
Allow autoloading to work as intended and avoid multiple requires.
Squashed! |
Include TagHelper but don't explicitly require it
@josevalim is it worthwhile to migrate the individual helper tests from |
We could do this move if it will basically be a class name change. If it requires rewriting many of the tests, I am -1. |
Certainly the intent would be to not touch the actual tests, just change the class and add any necessary setup. |
Allow autoloading to work as intended and avoid multiple requires.