This project is archived and is in readonly mode.
app/helpers within plugin not being mixed in
-
Jonah Fox
I found that by explicitly including the helper from plugin/init.rb, like:
require File.join(File.dirname(FILE), "app", "helpers", "users_helper.rb")
Is this expected behaviour ?
Thanks
-
Jonah Fox
--- meant to say ---
I found that it works if I explicitly include the helper from plugin/init.rb, like:
require File.join(File.dirname(FILE), "app", "helpers", "users_helper.rb")
Is this expected behaviour ?
Thanks
-
Jonah Fox
In fact this only works if there's already a users_helper.rb within the main project.
If not then I have to do:
ActionView::Base.send :include, UsersHelper;
within init.rb.
I think the same problem of having to explicitly include files may be true of models aswell.
Hope this helps
Jonah
-
Andrew White
Whether it's the desired behaviour for helper :all to include all of the helpers in engines as well as application helpers is something that probably needs to be discussed on the rails core mailing list. However the change is easy if you want to create a patch - just add "#{RAILS_ROOT}/vendor/plugins//app/helpers//*_helper.rb" to the Dir[] call in ActionController::Helpers.all_application_helpers.
You don't need to call ActionView::Base.send in the engine's init.rb file - you can just use helper :helper_name in ApplicationController. It's arguable that this the preferred behaviour since the developer may be using a engine developed by someone else and may be unaware of conflicting helper methods defined in a engine's helper file.
-
Andrew White
That path should've been: "#{RAILS_ROOT}/vendor/plugins/**/app/helpers/**/*_helper.rb"
-
Josh N. Abbott
It would seem to me that in order to remain consistent with the fact that controllers, models and views are getting included, the helpers should be included by default as well.
Thanks for the patch either way.
-- Josh
-
shm
it seems though, that the helper modules inside plugins/engines are added to the load_path, so if you specify your helper manually inside your controllers, it should work fine.
helper :my_plugin_helper
..only the "helper :all" approach doesn't work for helper-files inside engines.
(the "helper" method in your controller 'constantizes' the corresponding module-name and includes it into ActionView::Base).
-
James Adam
It does seem sensible that helper :all would load all helpers, even those in plugins.
One minor wrinkle is that it still wouldn't be possible for gems to provide helpers, unless they're stored in the vendor directory. This would be quite easy to implement if Ticket #2526 was deemed worthy.
Regardless, adding helpers underneath
vendor/plugins/**/app/helpersandvendor/gems/**/app/helpersseems like a great first step. -
adlongwell
+1 I agree with James.
-
jesse (at jesseclark)
+1 for plugin helpers getting picked up by helpers :all
-
Daniel Guettler
- Tag changed from engines, helpers, plugins to engines, helpers, patch, plugins, test
+1, I had this added in older Rails versions as well. I attached an actual patch to make this happen.
-
Jeremy Kemper
- Assigned user set to Jeremy Kemper
Rather than have two separate settings for specific directories, how about changing this to an array of helper paths instead?
-
Victor Costan
It's really sadist to have bugs like this lying around. I spent over an hour trying to figure out what's broken in my plugin, because I was getting my controllers included but not my helpers.
-
Andrea Zaupa
- Importance changed from to
This could help ?
only mixin in all helpers in the plugins with ApplicationController.helper .
in init.rb
Include hook code here
config.to_prepare do
(Dir[File.dirname(FILE) + "/app/helpers/_helper.rb"]+Dir[File.dirname(FILE) + "/app/helpers/**/_helper.rb"]).each do |file|
h ="Admin::#{File.basename(file, '.rb').gsub(/_helper$/, '').camelize}Helper".constantize ApplicationController.helper hend
end
-
Daniel Guettler
@Jeremy : The reason why I kept them separate is because they need slightly different treatment to actually get the helpers. Therefor I think it is best to keep this separated. I'm using this patch in production since I posted it without any problems. I think this patch should be applied to the 2.x branch to save people the time of debugging it.
-
Antonio Tapiador
+1 for plugin helpers getting picked up by helpers :all This is what I expected, I was in the same situation than Victor!
-
Piotr Sarnacki
Could you check your gems/plugins against rails/master? It should already work there: http://github.com/rails/rails/blob/master/railties/test/railties/en... I did this as a part of my work on extending engines.
-
José Valim
- State changed from open to resolved
- Assigned user changed from Jeremy Kemper to José Valim
Fixed on master.
-
Piotr Sarnacki
For those who can't use rails master and don't want to wait for 3.1, I've created small railtie that fixes problem described in that ticket: http://github.com/drogus/rails_helpers_fix
Just add that line to Gemfile and run bundle install:
gem "rails_helpers_fix" -
Robert Glaser
Thanks for providing this Hotfix, Piotr! But there's an issue with that: If there's a helper FooHelper in the main app, and a FooHelper in the engine/plugin, this doesn't work. It only works if the engine/plugin helpers is being renamed to an unused name.
-
Piotr Sarnacki
Oops, that's weird. I'll fix it today.
-
Piotr Sarnacki
Robert Glaser: After looking at code and rethinking that, I think the only sane way to handle that is namespacing helpers in your plugin. From Ruby point of view, declaring module twice will work since second one will just reopen first module, but it will be hard to change a way of loading helper files in Rails.
