Permalink
Browse files

Delegate ActionView::Base#controller_name to controller

  • Loading branch information...
1 parent b440aeb commit 0ad0bdc01c4fe2d66dd2b405433186824e7ce136 @lifo lifo committed Jun 10, 2008
Showing with 13 additions and 4 deletions.
  1. +1 −1 actionpack/lib/action_view/base.rb
  2. +12 −3 actionpack/test/controller/new_render_test.rb
@@ -184,7 +184,7 @@ def self.cache_template_extensions=(*args)
attr_internal :request
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
- :flash, :logger, :action_name, :to => :controller
+ :flash, :logger, :action_name, :controller_name, :to => :controller
module CompiledTemplates #:nodoc:
# holds compiled template code
@@ -220,7 +220,7 @@ def render_to_string_with_assigns
render :action => "test/hello_world"
end
- def render_to_string_with_partial
+ def render_to_string_with_partial
@partial_only = render_to_string :partial => "partial_only"
@partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") }
render :action => "test/hello_world"
@@ -251,11 +251,15 @@ def accessing_request_in_template
def accessing_logger_in_template
render :inline => "<%= logger.class %>"
end
-
+
def accessing_action_name_in_template
render :inline => "<%= action_name %>"
end
+ def accessing_controller_name_in_template
+ render :inline => "<%= controller_name %>"
+ end
+
def accessing_params_in_template_with_layout
render :layout => nil, :inline => "Hello: <%= params[:name] %>"
end
@@ -559,12 +563,17 @@ def test_access_to_logger_in_view
get :accessing_logger_in_template
assert_equal "Logger", @response.body
end
-
+
def test_access_to_action_name_in_view
get :accessing_action_name_in_template
assert_equal "accessing_action_name_in_template", @response.body
end
+ def test_access_to_controller_name_in_view
+ get :accessing_controller_name_in_template
+ assert_equal "test", @response.body # name is explicitly set to 'test' inside the controller.
+ end
+
def test_render_xml
get :render_xml_hello
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body

1 comment on commit 0ad0bdc

Contributor

rsl commented on 0ad0bdc Jun 10, 2008

The Swiss Bank is open!

Please sign in to comment.