Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

helper :all on by default

#3945

I cannot find the place to turn off the automatic loading for helper :all. I have controllers and views using helpers defined outside of application and its own controllers, yet it is still being loaded.

Reported by Ho-Sheng Hsiao · February 13th, 2010 @ 06:34 AM

State: duplicate
Milestone: none
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: Low

Activity

  1. Brian Rose
    Brian Rose
    • Assigned user set to Ryan Bigg
    • Tag changed from rails 3.0 beta to rails 3.0 beta, actioncontroller, helpers

    Rails 3.0 does not appear to support disabling auto-load of helpers. ApplicationController::Base does the following:

    def self.inherited(klass)
      ::ActionController::Base.subclasses << klass.to_s
      super
      klass.helper :all
    end
    

    Since this is not a bug, do you want this filed as a feature request for a future release?

    April 13th, 2010 @ 01:22 AM

  2. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to open
    • Milestone cleared.

    I agree. It should be possible to turn this off without creating your own Metal subclass and including all the modules manually.

    April 13th, 2010 @ 05:52 AM

  3. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • Assigned user changed from Ryan Bigg to Yehuda Katz (wycats)

    April 13th, 2010 @ 05:52 AM

  4. Felipe Rodrigues
    Felipe Rodrigues

    I'm working on a patch for this one.

    April 13th, 2010 @ 03:37 PM

  5. DHH
    DHH
    • State changed from open to needs-more-info

    Ho-Sheng, what's the problem you're trying to solve? Why do you want to turn off helpers?

    April 13th, 2010 @ 05:16 PM

  6. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from needs-more-info to invalid

    You should be able to achieve this by doing something like:

    class ActionController::WithoutHelpers < ActionController::Metal
      # includes all the modules, but doesn't get the inherited hook,
      # which is defined on the class itself
      include *ActionController::Base.without([])
    end
    
    class MyController < ActionController::WithoutHelpers
    end
    

    If this doesn't work for some reason, it's a bug.

    April 13th, 2010 @ 06:02 PM

  7. Ho-Sheng Hsiao
    Ho-Sheng Hsiao

    I think I need to clarify.

    I was using the first Rails 3.0 Beta for a project, the weekend it was released. I'm not sure why the timestamp for this issue says Apr 13th. According to my project commits, this issue came up Feb 13th, 2010 and I had thought I submitted the issue then. I've already worked around this and finished the project so I am fuzzy on the details. I have:

    class Admin::FeaturesController < ActionController

    # ...
    

    end

    class Manage::FeaturesController < ActionController

    # ...
    

    end

    module Admin::FeaturesHelper

    def render_edit_features(lender)
      render :partial => 'admin/features/edit_features', :locals => { :lender => lender }                                                                                        
    end
    

    end

    module Manage::FeaturesHelper

    def render_edit_features(lender)
      render :partial => 'manage/features/edit_features', :locals => { :lender => lender }                                                                                        
    end
    

    end

    Since I did not have

    class ApplicationController < ActionController::Base

    helpers :all
    

    end

    but rather something like

    class ApplicationController < ActionController::Base

    #helpers :all
    

    end

    I was expecting Rails 2 behavior where Admin::FeaturesController loads only Admin::FeaturesHelper but not Manage::FeaturesHelper. This was not the case, and the methods stepped on each other. I worked around this by renaming Manage::FeaturesHelper#render_edit_features to Manage::FeaturesHelper#render_edit_manage_features and moved on.

    I have no idea if this got caught and fixed in the second beta release. I'm certainly not asking for the ability to turn off all helpers, but I'm glad that got brought up. I'm working on a web services project that has no view layer and no helper layer, so down the road, I may want turn off all helpers ... but it isn't really critical. My original issue has to do with the helpers :all declaration.

    April 13th, 2010 @ 11:08 PM

  8. Ho-Sheng Hsiao
    Ho-Sheng Hsiao

    Messed up the formatting. Here are the codeblocks again:

    class Admin::FeaturesController < ActionController
      # ...
    end
    
    class Manage::FeaturesController < ActionController
      # ...
    end
    
    module Admin::FeaturesHelper
      def render_edit_features(lender)
        render :partial => 'admin/features/edit_features', :locals => { :lender => lender }                                                                                        
      end
    end
    
    module Manage::FeaturesHelper
      def render_edit_features(lender)
        render :partial => 'manage/features/edit_features', :locals => { :lender => lender }                                                                                        
      end
    end
    

    April 13th, 2010 @ 11:11 PM

  9. jbc
    jbc

    I'm in the same boat as Ho-Sheng Hsiao.

    I tend to use generic method names in views such as destroy_link_for(object) or format_date(date) and specify the exact desired behaviour in the appropriate controller's helper.

    If I want to make a method globally available, I put in in application_helper.rb

    Combing through all my helpers, ensuring that I'm not reusing a method name each time... is not fun, and could lead to all kinds of entertaining bugs.

    Not being able to use nice generic intent-descriptive methods in views is rather ugly too, IMHO.

    A config option to turn off the auto-all feature would be highly appreciated.

    May 12th, 2010 @ 05:06 AM

  10. Mat Schaffer
    Mat Schaffer

    Bump. Just ran into this today.

    Mixing in all helpers into every renderer pretty much defeats the purpose of having per-controller helpers. With the current behavior, you may as well just put everything in ApplicationHelper.

    May 26th, 2010 @ 09:51 PM

  11. Ho-Sheng Hsiao
    Ho-Sheng Hsiao

    @jbc, @Mat since this ticket got marked invalid for some reason, I think we're better off coming up with a patch.

    May 26th, 2010 @ 10:00 PM

  12. Mat Schaffer
    Mat Schaffer

    Sure would. I put it on my list of things to try to fix. But in the meantime:

    @yehuda: is there some reason for this behavior? Performance maybe?

    May 26th, 2010 @ 10:22 PM

  13. Brian Durand
    Brian Durand

    +1 for me. I'm having the same issue with an admin interface that uses the same method names as the public interface but require different outputs.

    June 1st, 2010 @ 09:17 PM

  14. tonycoco
    tonycoco

    +1, the solution in Rails 2 was much more elegant and made sense (if you want it, we got it, if you don't, comment it out). Yehuda's solution looks very Java-esk and extremely confusing... what is the "*" for?!? Does anyone comprehend that code by just reading over it? Probably not without a serious double-take. DHH's original design for inclusion of all helpers seemed to be fine to me.

    June 1st, 2010 @ 09:54 PM

  15. DHH
    DHH
    • Milestone cleared.
    • Assigned user cleared.

    I'm all for someone to wrap up pretty solution that opts out of all helpers, but before it was the alternative. You needed an extra line in your controller to get the default behavior of all helpers all the time.

    I could see something like "self.autoload_helpers = false" (could use better naming). After that's set, you'll have to manually declare helpers. Please open a new ticket if you want to pursue that.

    June 1st, 2010 @ 09:58 PM

  16. Ho-Sheng Hsiao
    Ho-Sheng Hsiao

    I have added #4750 Add feature, turning off autoloading helpers with a proposal for the configuration flags to fix this.

    June 1st, 2010 @ 11:09 PM

  17. Jeremy Kemper
    Jeremy Kemper
    • State changed from invalid to duplicate
    • Importance changed from to Low

    August 26th, 2010 @ 04:37 AM

  18. Jonathan
    Jonathan
    • Assigned user set to Yehuda Katz (wycats)

    Can the rails core team please provide just one good reason why all helpers should be included in every controller? What's the point of separate helper files then? Why not put everything in application_helper? I don't see any application of decent size wanting to include all helpers. Most large apps are unusable in rails 3 for this absurd change. And we don't even have an option to disable it? Yeah, we can do some hack like what Yehuda suggested, but I think the rails master branch even breaks that. What happened to modularity and choice? This is one pretty bold assumption to make. It is ridiculous that it is the default, but even more preposterous that we have no option. You guys have done great things with Rails 3, no doubt, but it looks like the mantra still lives on, if 37signals doesn't need it, the rest of the community doesn't.

    September 9th, 2010 @ 12:42 AM

  19. bingbing
  20. jackal
    jackal

    very nice pictures is also very lively and attractive you look .every one who wanted to congratulate you You look super. Ankara nakliyat A wonderful picture,nakliyat ankara and always such a special and very attractive as well stay beautiful ok Ankara evden eve nakliyat Ankara nakliye

    April 11th, 2011 @ 09:55 PM