我有两个模型类,用于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