Forum: Ruby on Rails RESTful multiple objects via one form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1df9fc8ddf084661265bbae74a8d0b43?d=identicon&s=25 jko170 (Guest)
on 2007-03-02 00:45
(Received via mailing list)
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.
1df9fc8ddf084661265bbae74a8d0b43?d=identicon&s=25 jko170 (Guest)
on 2007-03-02 03:21
(Received via mailing list)
Maybe I have to make a :collection => :post method?
1df9fc8ddf084661265bbae74a8d0b43?d=identicon&s=25 jko170 (Guest)
on 2007-03-02 06:05
(Received via mailing list)
Anyone else run into this problem?
3d9de7385f3767831cd228daef5650f9?d=identicon&s=25 Yottameter (Guest)
on 2007-03-02 06:06
(Received via mailing list)
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!
This topic is locked and can not be replied to.