mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add temporary support for passing locals to render using string keys
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2630 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
9369137676
commit
e625d27633
3 changed files with 18 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Add temporary support for passing locals to render using string keys [Nicholas Seckar]
|
||||||
|
|
||||||
* Clean up error pages by providing better backtraces [Nicholas Seckar]
|
* Clean up error pages by providing better backtraces [Nicholas Seckar]
|
||||||
|
|
||||||
* Raise an exception if an attempt is made to insert more session data into the ActiveRecordStore data column than the column can hold. #2234. [justin@textdrive.com]
|
* Raise an exception if an attempt is made to insert more session data into the ActiveRecordStore data column than the column can hold. #2234. [justin@textdrive.com]
|
||||||
|
|
|
@ -357,9 +357,12 @@ module ActionView #:nodoc:
|
||||||
locals_keys = @@template_args[render_symbol].keys | locals
|
locals_keys = @@template_args[render_symbol].keys | locals
|
||||||
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
||||||
|
|
||||||
locals_code = locals_keys.inject("") do |code, key|
|
locals_code = ""
|
||||||
|
unless locals_keys.empty?
|
||||||
|
locals_code << locals_keys.inject("local_assigns = local_assigns.symbolize_keys\n") do |code, key|
|
||||||
code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
|
code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,6 +80,11 @@ class TestController < ActionController::Base
|
||||||
render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { :local_name => name }
|
render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { :local_name => name }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accessing_local_assigns_in_inline_template_with_string_keys
|
||||||
|
name = params[:local_name]
|
||||||
|
render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { "local_name" => name }
|
||||||
|
end
|
||||||
|
|
||||||
def rescue_action(e) raise end
|
def rescue_action(e) raise end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -217,6 +222,12 @@ class RenderTest < Test::Unit::TestCase
|
||||||
assert_equal "Goodbye, Local David", process_request.body
|
assert_equal "Goodbye, Local David", process_request.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_accessing_local_assigns_in_inline_template_with_string_keys
|
||||||
|
@request.action = "accessing_local_assigns_in_inline_template_with_string_keys"
|
||||||
|
@request.query_parameters[:local_name] = "Local David"
|
||||||
|
assert_equal "Goodbye, Local David", process_request.body
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def process_request
|
def process_request
|
||||||
TestController.process(@request, @response)
|
TestController.process(@request, @response)
|
||||||
|
|
Loading…
Reference in a new issue