This project is archived and is in readonly mode.

#3945 ✓duplicate
Ho-Sheng Hsiao

helper :all on by default

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

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.

Comments and changes to this ticket

  • Brian Rose

    Brian Rose April 13th, 2010 @ 01:22 AM

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

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) April 13th, 2010 @ 05:52 AM

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

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) April 13th, 2010 @ 05:52 AM

    • Assigned user changed from “Ryan Bigg” to “Yehuda Katz (wycats)”
  • Felipe Rodrigues

    Felipe Rodrigues April 13th, 2010 @ 03:37 PM

    I'm working on a patch for this one.

  • DHH

    DHH April 13th, 2010 @ 05:16 PM

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

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) April 13th, 2010 @ 06:02 PM

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

  • Ho-Sheng Hsiao

    Ho-Sheng Hsiao April 13th, 2010 @ 11:08 PM

    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.

  • Ho-Sheng Hsiao

    Ho-Sheng Hsiao April 13th, 2010 @ 11:11 PM

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

    jbc May 12th, 2010 @ 05:06 AM

    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.

  • Mat Schaffer

    Mat Schaffer May 26th, 2010 @ 09:51 PM

    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.

  • Ho-Sheng Hsiao

    Ho-Sheng Hsiao May 26th, 2010 @ 10:00 PM

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

  • Mat Schaffer

    Mat Schaffer May 26th, 2010 @ 10:22 PM

    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?

  • Brian Durand

    Brian Durand June 1st, 2010 @ 09:17 PM

    +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.

  • tonycoco

    tonycoco June 1st, 2010 @ 09:54 PM

    +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.

  • DHH

    DHH June 1st, 2010 @ 09:58 PM

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

  • Ho-Sheng Hsiao

    Ho-Sheng Hsiao June 1st, 2010 @ 11:09 PM

    I have added #4750 with a proposal for the configuration flags to fix this.

  • Jeremy Kemper

    Jeremy Kemper August 26th, 2010 @ 04:37 AM

    • State changed from “invalid” to “duplicate”
    • Importance changed from “” to “Low”
  • Jonathan

    Jonathan September 9th, 2010 @ 12:42 AM

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

  • bingbing
  • jackal

    jackal April 11th, 2011 @ 09:55 PM

    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

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages