Ticket #10814: render_partial_builder.diff
| File render_partial_builder.diff, 4.5 kB (added by djanowski, 6 months ago) |
|---|
-
actionpack/test/controller/new_render_test.rb
old new 17 17 end 18 18 end 19 19 20 class LabellingFormBuilder < ActionView::Helpers::FormBuilder 21 end 22 20 23 class NewRenderTestController < ActionController::Base 21 24 layout :determine_layout 22 25 … … 136 139 def partial_with_locals 137 140 render :partial => "customer", :locals => { :customer => Customer.new("david") } 138 141 end 142 143 def partial_with_form_builder 144 render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, nil, Proc.new {}) 145 end 139 146 147 def partial_with_form_builder_subclass 148 render :partial => LabellingFormBuilder.new(:post, nil, @template, nil, Proc.new {}) 149 end 150 140 151 def partial_collection 141 152 render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ] 142 153 end … … 685 696 assert_equal "Hello: david", @response.body 686 697 end 687 698 699 def test_partial_with_form_builder 700 get :partial_with_form_builder 701 assert_match(/<label/, @response.body) 702 assert_template('test/_form') 703 end 704 705 def test_partial_with_form_builder_subclass 706 get :partial_with_form_builder_subclass 707 assert_match(/<label/, @response.body) 708 assert_template('test/_labelling_form') 709 end 710 688 711 def test_partial_collection 689 712 get :partial_collection 690 713 assert_equal "Hello: davidHello: mary", @response.body -
actionpack/test/fixtures/test/_labelling_form.erb
old new -
actionpack/test/fixtures/test/_form.erb
old new -
actionpack/lib/action_view/partials.rb
old new 119 119 else 120 120 render("#{path}/_#{partial_name}", local_assigns) 121 121 end 122 when ActionView::Helpers::FormBuilder 123 builder_partial_path = partial_path.class.to_s.demodulize.underscore.sub(/_builder$/, '') 124 render_partial(builder_partial_path, object_assigns, (local_assigns || {}).merge(builder_partial_path.to_sym => partial_path)) 122 125 when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Associations::HasManyThroughAssociation 123 126 if partial_path.any? 124 127 path = ActionController::RecordIdentifier.partial_path(partial_path.first) -
actionpack/lib/action_view/helpers/form_helper.rb
old new 32 32 # <input name="commit" type="submit" value="Create" /> 33 33 # </form> 34 34 # 35 # If you are using a partial for your form fields, you can use this shortcut: 36 # 37 # <% form_for :person, @person, :url => { :action => "create" } do |f| %> 38 # <%= render :partial => f %> 39 # <%= submit_tag 'Create' %> 40 # <% end %> 41 # 42 # This example will render the <tt>people/_form</tt> partial, setting a local variable called <tt>form</tt> which references the yielded FormBuilder. 43 # 35 44 # The <tt>params</tt> object created when this form is submitted would look like: 36 45 # 37 46 # {"action"=>"create", "controller"=>"persons", "person"=>{"first_name"=>"William", "last_name"=>"Smith"}} … … 153 162 # <%= check_box_tag "person[admin]", @person.company.admin? %> 154 163 # <% end %> 155 164 # 165 # In this case, if you use this: 166 # 167 # <%= render :partial => f %> 168 # 169 # The rendered template is <tt>people/_labelling_form</tt> and the local variable referencing the form builder is called <tt>labelling_form</tt>. 170 # 156 171 # In many cases you will want to wrap the above in another helper, so you could do something like the following: 157 172 # 158 173 # def labelled_form_for(record_or_name_or_array, *args, &proc)