diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 11 | ||||
-rw-r--r-- | actionpack/lib/action_view/base.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 22 |
3 files changed, 34 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index be0a4f4ace..c4774df274 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,16 @@ *SVN* +* Added locals hash to partials, which makes for convenient access of some times available/some times not variables #5491 [wbruce@gmail.com]. Example: + + # two different render calls + render :partial => "person", :locals => { :include_overview => true } + render :partial => "person" + + # view + <% if locals[:include_overview] %> + Show overview + <% end %> + * Fixed FormOptionsHelper#select to respect :selected value #5813 * Fixed TextHelper#simple_format to deal with multiple single returns within a single paragraph #5835 [moriq@moriq.com] diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index f3e2347d45..d8e4f80e99 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -456,7 +456,7 @@ 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_code = "locals = local_assigns.with_indifferent_access\n" locals_keys.each do |key| locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n" end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index c22702acd0..12340e56a6 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -93,6 +93,28 @@ class TestController < ActionController::Base ActionView::Base.local_assigns_support_string_keys = false end + def accessing_locals_hash_in_inline_template + name = params[:local_name] + render :inline => "<%= 'Goodbye, ' + locals[:local_name] %>", + :locals => { :local_name => name } + end + + def accessing_locals_hash_in_inline_template_setting_string_key + name = params[:local_name] + ActionView::Base.local_assigns_support_string_keys = true + render :inline => "<%= 'Goodbye, ' + locals[:local_name] %>", + :locals => { "local_name" => name } + ActionView::Base.local_assigns_support_string_keys = false + end + + def accessing_locals_hash_in_inline_template_getting_string_key + name = params[:local_name] + ActionView::Base.local_assigns_support_string_keys = true + render :inline => "<%= 'Goodbye, ' + locals['local_name'] %>", + :locals => { :local_name => name } + ActionView::Base.local_assigns_support_string_keys = false + end + def render_to_string_test @foo = render_to_string :inline => "this is a test" end |