我正在尝试创建一个应用程序,让教师能够每天选择不在学校的学生。我通过 nifty-generators gem 创建了模型。问题是它不会提交给 notpresents 表。请帮忙。
# == Schema Information
#
# Table name: students
#
# id :integer not null, primary key
# name :string(255)
# group_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Student < ActiveRecord::Base
attr_accessible :name, :group_id
belongs_to :days
end
# == Schema Information
#
# Table name: notpresents
#
# id :integer not null, primary key
# student_id :integer
# day_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Notpresent < ActiveRecord::Base
attr_accessible :student_id, :day_id
belongs_to :days
end
# == Schema Information
#
# Table name: days
#
# id :integer not null, primary key
# title :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class Day < ActiveRecord::Base
attr_accessible :title, :presents
has_many :notpresents
accepts_nested_attributes_for :notpresents
end
并查看_form.html.erb
<%= form_for @day do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<% for student in Student.find(:all) %>
<div>
<%= check_box_tag :notpresents, student.id%>
<%= student.name %>
</div>
<% end %>
<p><%= f.submit %></p>
<% end %>