diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/base.rb | 7 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 11 |
3 files changed, 18 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index acf6777daf..bc925e9c70 100644 --- a/actionpack/CHANGELOG +++ b/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] diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index c65faeafbd..f9b35260bd 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -357,8 +357,11 @@ module ActionView #:nodoc: 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" diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index cd7c32e0a2..f7cf77c204 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -79,6 +79,11 @@ class TestController < ActionController::Base 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 @@ class RenderTest < Test::Unit::TestCase @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 |