Monday 21 January 2013

undefined method to_i in rails 3.2.11 upgrade

I created my rails application using Rails 3.2.3 version. After some period i come to know Rails 3.2.3 having some security issues, Here i have mentioned what is the issue

What is the exact security issue in Rails 3.2.3

People told that if we upgrade rails 3.2.3 into rails 3.2.11 issue will resolve otherwise we have to do some code tweaks for supporting rails 3.2.3 code base.

So we upgrade into rails 3.2.11. Now security issue was over But found some other issue called "undefined method to_i" error in few of the places. After search in Google, we come up with solutions

In rails 3.2.3
doctor = Doctor.first
patient = Patient.new
patient.doctor_id =doctor (Right side Object assignment is valid)
patient.save! (valid)

In rails 3.2.11
doctor = Doctor.first
patient = Patient.new
patient.doctor_id = doctor (Right side Object assignment is invalid)
patient.save! (invalid)
NoMethodError: undefined method 'to_i' error we got this kind of assignments.

patient.doctor = doctor (is valid both left and right side are object reference)


So conclusion is we must use wherever _id column definition have to use INTEGER type only not just Object assignments. 

No comments :

Post a Comment