0
我試圖保存模型,稱爲申請人與嵌套工作和教育模型。保存模型時,我得到:無法批量分配受保護的屬性:works_attributes,rails嵌套模型中的educations_attributes
無法批量分配受保護的屬性: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
其工作,但工作模型數據不會保存到數據庫 – 2013-04-18 09:26:22
要保存工作模型數據,你必須通過你的申請人控制器中的值創建方法 – 2013-04-18 09:30:22
我該如何通過他們...你能幫我那 – 2013-04-18 09:39:15