Inserting data in a table with a varchar key field


#1

Hi all,
I have some problems inserting data into a legacy table. the key field
of this table is a field named CIN which is a varchar(15).
when I try insert into this table using a form (generated by the
scaffold generator) I get this Error :


undefined method `CIN_before_type_cast’ for #Candidat:0x370d8c8 |
|
Extracted source (around line #6): |
|
3: |
4: |
5:

CIN
|
6: <%= text_field ‘candidat’, ‘CIN’ %>

|
7: |
8:

Nom
|
9: <%= text_field ‘candidat’, ‘NOM_CANDIDAT’ %>

|
_____________________________________________________________________|

Then I added the following methods to my Model (Candidat):


                                                                 |

def CIN_before_type_cast |
read_attribute(:CIN) |
end |
|
def CIN_before_type_cast=(input) |
write_attribute(:CIN, input) |
end |
_____________________________________________________________________|

when I retry to insert using the same form I get this error message :

  • CIN cannot be blank

Please help, I’m a beginner and still discovering Rails and Ruby


#2

Hi, you’ll need to update this database field within your table to allow
nulls. This should do the job.

Peace,

-Conrad


#3

Conrad T. wrote:

Hi, you’ll need to update this database field within your table to allow
nulls. This should do the job.

Peace,

-Conrad

Thank your for the reply,
I can’t set the field to allow because it’s the table primary key. I
even tried to do so but Mysql ignored my attempt to update this field.
Any idea ?