This project is archived and is in readonly mode.
helper :all on by default
-
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 endSince this is not a bug, do you want this filed as a feature request for a future release?
-
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.
-
Yehuda Katz (wycats)
- Assigned user changed from Ryan Bigg to Yehuda Katz (wycats)
-
Felipe Rodrigues
I'm working on a patch for this one.
-
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?
-
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 endIf this doesn't work for some reason, it's a bug.
-
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 } endend
module Manage::FeaturesHelper
def render_edit_features(lender) render :partial => 'manage/features/edit_features', :locals => { :lender => lender } endend
Since I did not have
class ApplicationController < ActionController::Base
helpers :allend
but rather something like
class ApplicationController < ActionController::Base
#helpers :allend
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
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
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
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
@jbc, @Mat since this ticket got marked invalid for some reason, I think we're better off coming up with a patch.
-
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?
-
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.
-
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.
-
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.
-
Ho-Sheng Hsiao
I have added #4750 Add feature, turning off autoloading helpers with a proposal for the configuration flags to fix this.
-
Jeremy Kemper
- State changed from invalid to duplicate
- Importance changed from to Low
-
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.
-
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