我有兩個模型類,用於EmployeeDetailActiveRecord的錯誤
class Designation < ActiveRecord::Base
attr_accessible :name
validates :name, presence: true, uniqueness: { case_sensitive: false }
has_many :employee_details
accepts_nested_attributes_for :employee_details
end
和
class EmployeeDetail < ActiveRecord::Base
belongs_to :Designation
attr_accessible :bloodGroup, :dob, :doc, :doj, :empId, :name, :panNo, :status, :Designation
end
我已經生成的默認支架。從EmployeeDetail頁面,當我嘗試創建並在指定文本框中輸入整數值時,它給我錯誤 ActiveRecord::AssociationTypeMismatch in EmployeeDetailsController#create Designation(#81846160) expected, got String(#75419260)
。
任何人都可以幫我理清這個問題嗎? EmployeeDetailController#創建: - DEF創建 @employee_detail = EmployeeDetail.new(PARAMS [:employee_detail])
respond_to do |format|
if @employee_detail.save
format.html { redirect_to @employee_detail, notice: 'Employee detail was successfully created.' }
format.json { render json: @employee_detail, status: :created, location: @employee_detail }
else
format.html { render action: "new" }
format.json { render json: @employee_detail.errors, status: :unprocessable_entity }
end
end
末
請附上您的'EmployeeDetailsController#create'方法的代碼。 – Thilo 2012-08-08 09:14:13
可能是它對你有幫助http://stackoverflow.com/questions/4249856/activerecordassociationtypemismatch-in-commentscontrollercreate – 2012-08-08 10:22:43