This project is archived and is in readonly mode.

#1905 ✓resolved
Jonah Fox

app/helpers within plugin not being mixed in

Reported by Jonah Fox | February 7th, 2009 @ 12:25 PM | in 3.x

I have a plugin (engine) with an app directory. Everything works fine except the plugin/app/helpers/* are not being mixed in.

To get the project to run I have to copy the modules to the app/helpers directory.

The helpers are being loaded however (I created a ZHelper in plugin/app/helpers/z_helper.rb and it was defined within the console)

Not sure how best to proceed - any advice?

BTW this is using the edge gem from

Comments and changes to this ticket

  • Jonah Fox

    Jonah Fox February 7th, 2009 @ 03:02 PM

    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 ?


  • Jonah Fox

    Jonah Fox February 7th, 2009 @ 03:03 PM

    --- 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 ?


  • Jonah Fox

    Jonah Fox February 7th, 2009 @ 03:26 PM

    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


  • Andrew White

    Andrew White February 7th, 2009 @ 07:05 PM

    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

    Andrew White February 7th, 2009 @ 07:10 PM

    That path should've been: "#{RAILS_ROOT}/vendor/plugins/**/app/helpers/**/*_helper.rb"

  • Josh N. Abbott

    Josh N. Abbott March 26th, 2009 @ 07:49 PM

    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

    shm March 28th, 2009 @ 07:18 PM

    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

    James Adam May 2nd, 2009 @ 03:30 PM

    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/helpers and vendor/gems/**/app/helpers seems like a great first step.

  • adlongwell

    adlongwell May 5th, 2009 @ 06:59 PM

    +1 I agree with James.

  • Jeremy Kemper

    Jeremy Kemper May 5th, 2009 @ 07:08 PM

    • State changed from “new” to “open”

    +1, plugins should expose their helper dirs

  • jesse (at jesseclark)

    jesse (at jesseclark) May 18th, 2009 @ 06:54 PM

    +1 for plugin helpers getting picked up by helpers :all

  • Daniel Guettler

    Daniel Guettler July 24th, 2009 @ 08:37 PM

    • 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

    Jeremy Kemper August 1st, 2009 @ 07:54 PM

    • 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?

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Victor Costan

    Victor Costan May 28th, 2010 @ 07:53 AM

    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

    Andrea Zaupa July 22nd, 2010 @ 11:26 AM

    • 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 h



  • Daniel Guettler

    Daniel Guettler July 22nd, 2010 @ 01:53 PM

    @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

    Antonio Tapiador September 24th, 2010 @ 03:52 PM

    +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

    Piotr Sarnacki September 25th, 2010 @ 12:40 AM

    Could you check your gems/plugins against rails/master? It should already work there: I did this as a part of my work on extending engines.

  • José Valim

    José Valim October 11th, 2010 @ 05:00 PM

    • State changed from “open” to “resolved”
    • Assigned user changed from “Jeremy Kemper” to “José Valim”

    Fixed on master.

  • Piotr Sarnacki

    Piotr Sarnacki October 12th, 2010 @ 03:31 PM

    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:

    Just add that line to Gemfile and run bundle install:

    gem "rails_helpers_fix"
  • Robert Glaser

    Robert Glaser October 19th, 2010 @ 11:37 AM

    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

    Piotr Sarnacki October 19th, 2010 @ 12:50 PM

    Oops, that's weird. I'll fix it today.

  • Piotr Sarnacki

    Piotr Sarnacki October 19th, 2010 @ 01:40 PM

    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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>