rails 2.3 + engines + helpers
Posted by michael.schaerfer on 28-Mar-09 at 20:50
According to this ticket #1905, app/helpers in rails plugins-engines doesn't get mixed into the ActionView::Base, and so the methods are not available in the views.
The reason for this is, that the "all_application_helpers" method in ActionController::Helper only returns the helper modules in RAILS_ROOT/app/helper and not those in vendor/plugins/**/app/helpers:
1 #file: action_controller/helpers.rb 2 #line: 219 3 # Extract helper names from files in app/helpers/**/*.rb 4 def all_application_helpers 5 extract = /^#{Regexp.quote(helpers_dir)}\/?(.*)_helper.rb$/ 6 Dir["#{helpers_dir}/**/*_helper.rb"].map { |file| file.sub extract, '\1' } 7 end 8
So when you say
1 helper :allin your controller, the helper-methods of your plugin are not available.
BUT, ... all the helper modules of your plugin are added to the load_path, so a quick fix for this problem would be to load the helper-module manually
1 # for every helper file in your engines: 2 helper :my_plugin_helper
Then the corresponding module-name is "constantized" and included into ActionView::Base by the "add_template_helper" method:
1 #file: action_controller/helpers.rb 2 #line: 75 3 def add_template_helper(helper_module) #:nodoc: 4 master_helper_module.module_eval { include helper_module } 5 end
..and all helper-methods of your plugin/engine are available in your views.

Comments
There are 0 comments on this post. Post yours →
Post a comment
Required fields in bold.