Reputation: 1936
I have two model class,
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
and
class EmployeeDetail < ActiveRecord::Base
belongs_to :Designation
attr_accessible :bloodGroup, :dob, :doc, :doj, :empId, :name, :panNo, :status, :Designation
end
I have generated default scaffold for EmployeeDetail. from EmployeeDetail page when i tried to create and enter integer value in designation textbox, it gives me error
ActiveRecord::AssociationTypeMismatch in EmployeeDetailsController#create
Designation(#81846160) expected, got String(#75419260)
.
can anyone help me to sortout this problem? 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
end
Upvotes: 0
Views: 162
Reputation: 775
When you associate any model, you should use the lowercase version of the model name.
Change:
belongs_to :Designation
to:
belongs_to :designation
Upvotes: 1