提交 250fb3f6 编写于 作者: P Piotr Sarnacki 提交者: José Valim

Add config.action_controller.include_all_helpers, by default it is set to true.

In older rails versions there was a way to use only helpers from
helper file corresponding to current controller and you could also
include all helpers by saying 'helper :all' in controller. This config
allows to return to older behavior by setting it to false.
上级 4d35f8b6
......@@ -53,8 +53,9 @@ module Helpers
include AbstractController::Helpers
included do
config_accessor :helpers_path
config_accessor :helpers_path, :include_all_helpers
self.helpers_path ||= []
self.include_all_helpers = true
end
module ClassMethods
......
......@@ -13,7 +13,9 @@ def self.with(app)
end
klass.helpers_path = paths
klass.helper :all if klass.superclass == ActionController::Base
if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
klass.helper :all
end
end
end
end
......
......@@ -65,6 +65,66 @@ def notify
assert_equal ["notify"], Foo.action_methods
end
test "allows to not load all helpers for controllers" do
add_to_config "config.action_controller.include_all_helpers = false"
app_file "app/controllers/application_controller.rb", <<-RUBY
class ApplicationController < ActionController::Base
end
RUBY
app_file "app/controllers/foo_controller.rb", <<-RUBY
class FooController < ApplicationController
def included_helpers
render :inline => "<%= from_app_helper -%> <%= from_foo_helper %>"
end
def not_included_helper
render :inline => "<%= respond_to?(:from_bar_helper) -%>"
end
end
RUBY
app_file "app/helpers/application_helper.rb", <<-RUBY
module ApplicationHelper
def from_app_helper
"from_app_helper"
end
end
RUBY
app_file "app/helpers/foo_helper.rb", <<-RUBY
module FooHelper
def from_foo_helper
"from_foo_helper"
end
end
RUBY
app_file "app/helpers/bar_helper.rb", <<-RUBY
module BarHelper
def from_bar_helper
"from_bar_helper"
end
end
RUBY
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
match "/:controller(/:action)"
end
RUBY
require 'rack/test'
extend Rack::Test::Methods
get "/foo/included_helpers"
assert_equal "from_app_helper from_foo_helper", last_response.body
get "/foo/not_included_helper"
assert_equal "false", last_response.body
end
# AD
test "action_dispatch extensions are applied to ActionDispatch" do
add_to_config "config.action_dispatch.tld_length = 2"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册