Hope this helps... There might be typos, but I think it may lead you in the right direction... Not sure the most elegant direction
Just assuming that attendance model contains attendance_date, present, comment
Otherwise checkout Railscasts:
#196 Nested Model Form (revised).
<%= form_for @student , :url=> {:controller=>"student", :action => "list", :id => @
student.id} do |nf| %>
<table >
<tr >
<th >First Name</th>
<th >MI</th>
<th >Last Name</th>
</tr>
<tr >
<td ><%= nf.text_field(:first_name) %></td>
<td ><%= nf.text_field(:mi) %></td>
<td ><%= nf.text_field(:last_name) %></td>
</tr>
<%= nf.fields_for :attendances, @student.attendences do |builder| %>
<tr >
<td ><%= builder.text_field(:attendence_date) %></td>
<td ><%= builder.label :present, "Present?" %><%= builder.check_box :present %></td>
<td ><%= builder.text_field(:comment) %></td>
</tr>
<% end %>
<tr >
<td colspan=3 ><%= nf.submit "Add Attendence Record" %></td>
</tr>
</table>
<% end %>
Student Controller
def list
if params[:commit] == "Add Attendence Record"
if add
......
end
else
@student = Student.find(param[:id])
end
end
def add
@student = Student.find(params[:id])
@student.attendences << Attendance.new()
if @student.errors.empty?
return true
else
return false
end
end
Student Model
has_many :attendances, :dependent => :destroy
attr_accessible :attendances_attributes, :allow_destroy => true
accepts_nested_attributes_for :attendances
Attendence Model
belongs_to :student