Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit e625d276334bbfd1f0bc4359be2eea9fb75ae36a 1 parent 9369137
@seckar seckar authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add temporary support for passing locals to render using string keys [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]
View
7 actionpack/lib/action_view/base.rb
@@ -357,8 +357,11 @@ def create_template_source(extension, template, render_symbol, locals)
locals_keys = @@template_args[render_symbol].keys | locals
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
- locals_code = locals_keys.inject("") do |code, key|
- code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
+ 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"
+ end
end
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
View
11 actionpack/test/controller/render_test.rb
@@ -79,6 +79,11 @@ def accessing_local_assigns_in_inline_template
name = params[:local_name]
render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { :local_name => name }
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
@@ -216,6 +221,12 @@ def test_accessing_local_assigns_in_inline_template
@request.query_parameters[:local_name] = "Local David"
assert_equal "Goodbye, Local David", process_request.body
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
def process_request
Please sign in to comment.
Something went wrong with that request. Please try again.