Forum: Ruby on Rails Inserting data in a table with a varchar key field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
29c3acaa1567b8498f0c638d290c5539?d=identicon&s=25 The Allnighter (Guest)
on 2006-05-22 19:16
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: <!--[form:candidat]-->                                            |
4:                                                                   |
5: <p><label for="candidat_CIN">CIN</label><br/>                     |
6: <%= text_field 'candidat', 'CIN'  %></p>                          |
7:                                                                   |
8: <p><label for="candidat_NOM_CANDIDAT">Nom</label><br/>            |
9: <%= text_field 'candidat', 'NOM_CANDIDAT'  %></p>                 |
_____________________________________________________________________|

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
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2006-05-22 19:53
(Received via mailing list)
Hi, you'll need to update this database field within your table to allow
nulls.  This should do the job.

Peace,

-Conrad
29c3acaa1567b8498f0c638d290c5539?d=identicon&s=25 The Allnighter (Guest)
on 2006-05-22 20:11
Conrad Taylor 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 ?
This topic is locked and can not be replied to.