Skip to content

Commit

Permalink
Added locals hash to partials, which makes for convenient access of s…
Browse files Browse the repository at this point in the history
…ome times available/some times not variables (closes #5491) [wbruce@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4997 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Sep 4, 2006
1 parent 9390174 commit df70e28
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ 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_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
Expand Down
22 changes: 22 additions & 0 deletions actionpack/test/controller/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ def accessing_local_assigns_in_inline_template_with_string_keys
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
Expand Down

0 comments on commit df70e28

Please sign in to comment.