mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Delegate ivars to controller instead of copying
Reduce number of instance variables being copied from controller to view. Instead, delegate them to controller instance.
This commit is contained in:
parent
f757f58388
commit
a04f022877
4 changed files with 23 additions and 10 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Reduce number of instance variables being copied from controller to view. [Pratik]
|
||||
|
||||
* select_datetime and select_time default to Time.zone.now when config.time_zone is set [Geoff Buesing]
|
||||
|
||||
* datetime_select defaults to Time.zone.now when config.time_zone is set [Geoff Buesing]
|
||||
|
|
|
@ -256,7 +256,8 @@ module ActionController #:nodoc:
|
|||
|
||||
# Controller specific instance variables which will not be accessible inside views.
|
||||
@@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
|
||||
@action_name @before_filter_chain_aborted @action_cache_path)
|
||||
@action_name @before_filter_chain_aborted @action_cache_path @_session @_cookies @_headers @_params
|
||||
@_flash @_response)
|
||||
|
||||
# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
|
||||
# and images to a dedicated asset server away from the main web server. Example:
|
||||
|
|
|
@ -156,9 +156,6 @@ module ActionView #:nodoc:
|
|||
attr_reader :finder
|
||||
attr_accessor :base_path, :assigns, :template_extension, :first_render
|
||||
attr_accessor :controller
|
||||
|
||||
attr_reader :logger, :response, :headers
|
||||
attr_internal :cookies, :flash, :headers, :params, :request, :response, :session
|
||||
|
||||
attr_writer :template_format
|
||||
attr_accessor :current_render_extension
|
||||
|
@ -185,7 +182,10 @@ module ActionView #:nodoc:
|
|||
@@erb_variable = '_erbout'
|
||||
cattr_accessor :erb_variable
|
||||
|
||||
delegate :request_forgery_protection_token, :to => :controller
|
||||
attr_internal :request
|
||||
|
||||
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
|
||||
:flash, :logger, :to => :controller
|
||||
|
||||
module CompiledTemplates #:nodoc:
|
||||
# holds compiled template code
|
||||
|
@ -222,7 +222,6 @@ module ActionView #:nodoc:
|
|||
@assigns = assigns_for_first_render
|
||||
@assigns_added = nil
|
||||
@controller = controller
|
||||
@logger = controller && controller.logger
|
||||
@finder = TemplateFinder.new(self, view_paths)
|
||||
end
|
||||
|
||||
|
|
|
@ -239,6 +239,14 @@ class NewRenderTestController < ActionController::Base
|
|||
render :inline => "Hello: <%= params[:name] %>"
|
||||
end
|
||||
|
||||
def accessing_request_in_template
|
||||
render :inline => "Hello: <%= request.host %>"
|
||||
end
|
||||
|
||||
def accessing_logger_in_template
|
||||
render :inline => "<%= logger.class %>"
|
||||
end
|
||||
|
||||
def accessing_params_in_template_with_layout
|
||||
render :layout => nil, :inline => "Hello: <%= params[:name] %>"
|
||||
end
|
||||
|
@ -529,10 +537,13 @@ class NewRenderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_access_to_request_in_view
|
||||
get :hello_world
|
||||
assert !assigns.include?('request'), 'request should not be in assigns'
|
||||
assert_kind_of ActionController::AbstractRequest, assigns['_request']
|
||||
assert_kind_of ActionController::AbstractRequest, @response.template.request
|
||||
get :accessing_request_in_template
|
||||
assert_equal "Hello: www.nextangle.com", @response.body
|
||||
end
|
||||
|
||||
def test_access_to_logger_in_view
|
||||
get :accessing_logger_in_template
|
||||
assert_equal "Logger", @response.body
|
||||
end
|
||||
|
||||
def test_render_xml
|
||||
|
|
Loading…
Reference in a new issue