當我保存申請人模型時,它不會將嵌套模型數據保存到數據庫中。請幫我解決他的問題。我已經貼我的控制器代碼,型號代碼&傳遞參數不保存嵌套表單模型數據軌?
我的參數是:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"5F8h7qG2pez9Rsutnq3JXYyXbPkbVJAlgfIfsE1bdUw=", "applicant"=>
{"job_id"=>"1", "first_name"=>"sanyam", "location"=>"", "email"=>"", "mob_no"=>"", "alternative_no"=>"", "last_name"=>"jain", "works_attributes"=>{"1366604495995"=>
{"title"=>"M Tech", "company_name"=>"", "start_month"=>"", "start_year"=>"", "end_month"=>"", "end_year"=>"", "description"=>"", "_destroy"=>"false"}, "1366604506595"=>
{"title"=>"B Tech", "company_name"=>"", "start_month"=>"", "start_year"=>"", "end_month"=>"", "end_year"=>"", "description"=>"", "_destroy"=>"false"}}, "linkedin"=>"",
"twitter"=>"", "facebook"=>"", "message"=>""}, "submit"=>""}
我的控制器代碼是:
def createProfile
@applicant = Applicant.new(params[:applicant])
@applicant.save
end
我的申請人模型
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
attr_accessible :works_attributes, :educations_attributes
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
我的工作模式是
class Work < ActiveRecord::Base
attr_accessible :applicant_id, :company_name, :description, :end_month, :end_year, :start_month, :start_year, :title
belongs_to :applicant
validates_associated :applicant
end
在控制器用戶「保存!」而不是「救」與後募集錯誤 – 2013-04-22 04:39:31
還需要添加在申請人模型attr_accessable:works_attributes,:educations_Attributes – 2013-04-22 04:41:56
都嘗試這一點,它不工作 – 2013-04-22 04:56:17