RESTful multiple objects via one form


#1

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.


#2

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


#3

Anyone else run into this problem?


#4

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!