The Allnighter
2006-May-22 17:16 UTC
[Rails] Inserting data in a table with a varchar key field
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 -- Posted via http://www.ruby-forum.com/.
Conrad Taylor
2006-May-22 17:50 UTC
[Rails] Inserting data in a table with a varchar key field
Hi, you''ll need to update this database field within your table to allow nulls. This should do the job. Peace, -Conrad On 5/22/06, The Allnighter <theallnighter@gmail.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060522/b92d5b15/attachment.html
The Allnighter
2006-May-22 18:11 UTC
[Rails] Re: Inserting data in a table with a varchar key field
Conrad Taylor wrote:> Hi, you''ll need to update this database field within your table to allow > nulls. This should do the job. > > Peace, > > -ConradThank 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 ? -- Posted via http://www.ruby-forum.com/.