Changeset 8646
- Timestamp:
- 01/16/08 02:01:57 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/form_helper.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_view/partials.rb (modified) (1 diff)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (3 diffs)
- trunk/actionpack/test/fixtures/test/_form.erb (added)
- trunk/actionpack/test/fixtures/test/_labelling_form.erb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8637 r8646 1 1 *SVN* 2 3 * Make render :partial recognise form builders and use the _form partial. #10814 [djanowski] 2 4 3 5 * Allow users to declare other namespaces when using the atom feed helpers. #10304 [david.calavera] trunk/actionpack/lib/action_view/helpers/form_helper.rb
r8597 r8646 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 # … … 153 162 # <%= check_box_tag "person[admin]", @person.company.admin? %> 154 163 # <% end %> 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>. 155 170 # 156 171 # In many cases you will want to wrap the above in another helper, so you could do something like the following: trunk/actionpack/lib/action_view/partials.rb
r8136 r8646 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? trunk/actionpack/test/controller/new_render_test.rb
r8564 r8646 16 16 page.visual_effect :highlight 17 17 end 18 end 19 20 class LabellingFormBuilder < ActionView::Helpers::FormBuilder 18 21 end 19 22 … … 137 140 render :partial => "customer", :locals => { :customer => Customer.new("david") } 138 141 end 139 142 143 def partial_with_form_builder 144 render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, nil, Proc.new {}) 145 end 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") ] … … 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