我有两个模型课,
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 生成了默认脚手架。当我尝试在指定文本框中创建和输入整数值时,来自 EmployeeDetail 页面,它给了我错误
ActiveRecord::AssociationTypeMismatch in EmployeeDetailsController#create
Designation(#81846160) expected, got String(#75419260)
。
谁能帮我解决这个问题?EmployeeDetailController#create:- def create @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
结尾