Why can I access helper methods for one controller in the views for a different controller? Is there a way to disable this without hacking/patching Rails?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
Actually in Rails 2, the default functionality of ActionController::Base was to include all helpers.
Changeset 6222 on 02/24/07 20:33:47 (3 years ago) by dhh: Make it a default assumption that you want all helpers, all the time (yeah, yeah)
change:
As of Rails 3 beta 1, that is no longer the case as noted in the CHANGELOG:
@George Schreiber's method doesn't work as of Rails 3.1; the code has changed significantly.
However, there's now an even better way to disable this feature in Rails 3.1 (and hopefully later). In your config/application.rb, add this line:
This will prevent ApplicationController from loading all of the helpers.
(For anyone who is interested, here's the pull request where the feature was created.)
In Rails 3,
actioncontroller/base.rb
(around line 224):So yes, if you derive your class from
ActionController::Base
, all helpers will be included.To come around this, call
clear_helpers
(AbstractClass::Helpers
; included inActionController::Base
) at the beginning of your controller's code. Source code comment for clear_helpers:E.g.:
The answer depends on the Rails version.
Rails >= 3.1
Change the
include_all_helpers
config tofalse
in any environment where you want to apply the configuration. If you want the config to apply to all environments, change it inapplication.rb
.When false, it will skip the inclusion.
Rails < 3.1
Delete the following line from
ApplicationController
In this way each controller will load its own helpers.