Skip to content

Commit

Permalink
Apply [3157] to stable. Make ActionController's render honor the :loc…
Browse files Browse the repository at this point in the history
…als option when rendering a :file. Closes rails#1665.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3158 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
Marcel Molina committed Nov 22, 2005
1 parent 7bf86f2 commit 541da09
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Make ActionController's render honor the :locals option when rendering a :file. #1665. [Emanuel Borsboom, Marcel Molina Jr.]

* Strip out trailing &_= for raw post bodies. Closes #2868. [Sam Stephenson]

* Correct docs for automatic layout assignment. #2610. [Charles M. Gerungan]
Expand Down
10 changes: 7 additions & 3 deletions actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ def controller_name
self.class.controller_name
end

def session_enabled?
request.session_options[:disabled] != false
end

protected
# Renders the content that will be returned to the browser as the response body.
#
Expand Down Expand Up @@ -596,7 +600,7 @@ def render(options = nil, deprecated_status = nil) #:doc:

else
if file = options[:file]
render_file(file, options[:status], options[:use_full_path])
render_file(file, options[:status], options[:use_full_path], options[:locals] || {})

elsif template = options[:template]
render_file(template, options[:status], true)
Expand Down Expand Up @@ -644,11 +648,11 @@ def render_action(action_name, status = nil, with_layout = true)
end
end

def render_file(template_path, status = nil, use_full_path = false)
def render_file(template_path, status = nil, use_full_path = false, locals = {})
add_variables_to_assigns
assert_existance_of_template_file(template_path) if use_full_path
logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
render_text(@template.render_file(template_path, use_full_path), status)
render_text(@template.render_file(template_path, use_full_path, locals), status)
end

def render_template(template, status = nil, type = :rhtml, local_assigns = {})
Expand Down
31 changes: 31 additions & 0 deletions actionpack/test/controller/new_render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ def render_text_hello_world_with_layout
def render_custom_code
render :text => "hello world", :status => "404 Moved"
end

def render_file_with_instance_variables
@secret = 'in the sauce'
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.rhtml')
render :file => path
end

def render_file_with_locals
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.rhtml')
render :file => path, :locals => {:secret => 'in the sauce'}
end

def render_file_not_using_full_path
@secret = 'in the sauce'
render :file => 'test/render_file_with_ivar', :use_full_path => true
end

def render_xml_hello
@name = "David"
Expand Down Expand Up @@ -242,6 +258,21 @@ def test_do_with_render_custom_code
assert_response :missing
end

def test_render_file_with_instance_variables
get :render_file_with_instance_variables
assert_equal "The secret is in the sauce\n", @response.body
end

def test_render_file_not_using_full_path
get :render_file_not_using_full_path
assert_equal "The secret is in the sauce\n", @response.body
end

def test_render_file_with_locals
get :render_file_with_locals
assert_equal "The secret is in the sauce\n", @response.body
end

def test_attempt_to_access_object_method
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
end
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/fixtures/test/render_file_with_ivar.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The secret is <%= @secret %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The secret is <%= secret %>

0 comments on commit 541da09

Please sign in to comment.