Skip to content
This repository
Browse code

Accept String value for render_partial :as option

[#6222 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit 5dd803e9b1149f8e6d7de787e0c833c94f48d5a4 1 parent 6bd9fac
Akira Matsuda authored December 25, 2010 spastorino committed February 01, 2011
2  actionpack/lib/action_view/partials.rb
@@ -40,7 +40,7 @@ module ActionView
40 40
   # With the <tt>:as</tt> option we can specify a different name for said local variable. For example, if we
41 41
   # wanted it to be +agreement+ instead of +contract+ we'd do:
42 42
   #
43  
-  #   <%= render :partial => "contract", :as => :agreement %>
  43
+  #   <%= render :partial => "contract", :as => 'agreement' %>
44 44
   #
45 45
   # The <tt>:object</tt> option can be used to directly specify which object is rendered into the partial;
46 46
   # useful when the template's object is elsewhere, in a different ivar or in a local variable for instance.
4  actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -108,7 +108,7 @@ def find_partial
108 108
         locals << @variable_counter if @collection
109 109
         find_template(path, locals)
110 110
       end
111  
-    end 
  111
+    end
112 112
 
113 113
     def find_template(path=@path, locals=@locals.keys)
114 114
       prefixes = path.include?(?/) ? [] : @view.controller_prefixes
@@ -159,7 +159,7 @@ def partial_path(object = @object)
159 159
     end
160 160
 
161 161
     def retrieve_variable(path)
162  
-      variable = @options[:as] || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym
  162
+      variable = @options[:as].try(:to_sym) || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym
163 163
       variable_counter = :"#{variable}_counter" if @collection
164 164
       [variable, variable_counter]
165 165
     end
7  actionpack/test/template/render_test.rb
@@ -146,7 +146,12 @@ def test_render_partial_collection
146 146
     assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
147 147
   end
148 148
 
149  
-  def test_render_partial_collection_as
  149
+  def test_render_partial_collection_as_by_string
  150
+    assert_equal "david david davidmary mary mary",
  151
+      @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => 'customer')
  152
+  end
  153
+
  154
+  def test_render_partial_collection_as_by_symbol
150 155
     assert_equal "david david davidmary mary mary",
151 156
       @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer)
152 157
   end

0 notes on commit 5dd803e

Please sign in to comment.
Something went wrong with that request. Please try again.