我正在尝试使用嵌套工作和教育模型保存名为申请人的模型。保存模型时,我得到:
无法批量分配受保护的属性:works_attributes、educations_attributes 错误。
对于 nil:NilClass 的未定义方法“klass”,我也收到错误消息。我正在使用 Rails 3.2。
我的型号代码:
applicant.rb
class Applicant < ActiveRecord::Base
attr_accessible :first_name, :last_name, :location, :email, :mob_no, :alternative_no, :linkedin, :facebook, :twitter, :message, :resume, :job_id
has_many :works, :dependent => :destroy
has_many :educations, :dependent => :destroy
accepts_nested_attributes_for :works, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
accepts_nested_attributes_for :educations, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
end
work.rb
class Work < ActiveRecord::Base
attr_accessible :applicant_id, :company_name, :description, :end_month, :end_year, :start_month, :start_year, :title
belongs_to :applicant
end
education.rb
class Education < ActiveRecord::Base
attr_accessible :applicant_id, :end_month, :end_year, :institution_name, :major, :start_month, :start_year, :title
belongs_to :applicant
end