# RESTful multiple objects via one form

**URL:** <https://www.ruby-forum.com/t/restful-multiple-objects-via-one-form/87362>\
**Category:** Rails\
**Created:** [March 2, 2007, 12:45am UTC](https://www.ruby-forum.com/t/restful-multiple-objects-via-one-form/87362 "2007-03-02T00:45:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 2, 2007, 12:45am UTC](https://www.ruby-forum.com/t/restful-multiple-objects-via-one-form/87362/1 "2007-03-02T00:45:08Z")

</div>

I’ve looked at all the tutorials on how to create multiple objects of  
the same type with one form. However, I cannot get it to work with my  
REST app. This is what I have tried:

----- Controller ---------

‘new’ action ----------  
def new  
@students = []  
5.times { @students \<\< Student.new }  
end

‘create’ action ----------  
params[:students].values do |student|  
Student.new(student) unless student.values.all?(&:blank?)  
end

-------- View -----------  
\<% @students.each\_with\_index do |student, index| %\>  
\<% fields\_for “students[#{index}]”, student do |s| %\>  
\<%= render :partial =\> ‘students/student\_form’, :locals =\> {:f =\>  
s} %\>  
\<% end %\>  
\<% end %\>

I cannot figure out why this is not working. The objects will not get  
saved. Please help.

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 2, 2007, 3:21am UTC](https://www.ruby-forum.com/t/restful-multiple-objects-via-one-form/87362/2 "2007-03-02T03:21:23Z")

</div>

Maybe I have to make a :collection =\> :post method?

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 2, 2007, 6:05am UTC](https://www.ruby-forum.com/t/restful-multiple-objects-via-one-form/87362/3 "2007-03-02T06:05:32Z")

</div>

Anyone else run into this problem?

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 2, 2007, 6:06am UTC](https://www.ruby-forum.com/t/restful-multiple-objects-via-one-form/87362/4 "2007-03-02T06:06:33Z")

</div>

I’m not an expert, but no one else seems to be helping.

I’m familiar with 1.1.6 rails, just starting to use 1.2.

In the ‘old days’ in your create task, ‘new’ would just create the  
object in memory, similar to your ‘new’ task. ‘Back then’ you had to  
either obj.save! or do obj.create instead of obj.new.

Hope it helps you in some direction!
