Skip to content

Commit

Permalink
Add config.action_controller.include_all_helpers, by default it is se…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
drogus authored and josevalim committed Nov 17, 2010
1 parent 4d35f8b commit 250fb3f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
3 changes: 2 additions & 1 deletion actionpack/lib/action_controller/metal/helpers.rb
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion actionpack/lib/action_controller/railties/paths.rb
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions railties/test/application/initializers/frameworks_test.rb
Expand Up @@ -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"
Expand Down

0 comments on commit 250fb3f

Please sign in to comment.