Hi All, View ******** <tr> <td><b>Student: </b></td> <td><%= text_field "student", "fname", "size" => 40, "maxlength" => 40 %></td> </tr> <tr> <td><b>Program: </b></td> <td><select id="student_program_id" name="student[program_id]"> <%= options_from_collection_for_select @programs, "id", "prg_name", @student.program_id %> </select> </td> </tr> Model ******* class Student < ActiveRecord::Base belongs_to :program validates_presence_of :fname, :program end When I have the dropdown list with the available programs, the application doesn''t validates the text field if I try to create a record with blank "fname". However if remove the dropdownnlist, it checks whether fname is present or not. Could anyone tell what I am doing wrong here? Thanks Silvy Mathews
Try it with :program_id Bob Silva http://www.railtie.net/> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of Silvy@funmail.com > Sent: Thursday, February 02, 2006 11:37 AM > To: rails@lists.rubyonrails.org > Subject: [Rails] Doubts on validation > > Hi All, > View > ******** > <tr> > <td><b>Student: </b></td> > <td><%= text_field "student", "fname", "size" => 40, "maxlength" > => 40 %></td> > </tr> > <tr> > <td><b>Program: </b></td> > <td><select id="student_program_id" name="student[program_id]"> > <%= options_from_collection_for_select @programs, "id", > "prg_name", @student.program_id %> > </select> > </td> > </tr> > > Model > ******* > class Student < ActiveRecord::Base > belongs_to :program > validates_presence_of :fname, :program > end > > > > When I have the dropdown list with the available programs, the > application doesn''t validates the text field if I try to create a record > with blank "fname". However if remove the dropdownnlist, it checks > whether fname is present or not. Could anyone tell what I am doing wrong > here? > > Thanks > Silvy Mathews > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Bob, It did not work either. I do not know what I am doing wrong? Thanks Silvy -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Bob Silva Sent: Thursday, February 02, 2006 3:37 PM To: rails@lists.rubyonrails.org Subject: RE: [Rails] Doubts on validation Try it with :program_id Bob Silva http://www.railtie.net/> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of Silvy@funmail.com > Sent: Thursday, February 02, 2006 11:37 AM > To: rails@lists.rubyonrails.org > Subject: [Rails] Doubts on validation > > Hi All, > View > ******** > <tr> > <td><b>Student: </b></td> > <td><%= text_field "student", "fname", "size" => 40, "maxlength" > => 40 %></td> > </tr> > <tr> > <td><b>Program: </b></td> > <td><select id="student_program_id" name="student[program_id]"> > <%= options_from_collection_for_select @programs, "id", > "prg_name", @student.program_id %> > </select> > </td> > </tr> > > Model > ******* > class Student < ActiveRecord::Base > belongs_to :program > validates_presence_of :fname, :program end > > > > When I have the dropdown list with the available programs, the > application doesn''t validates the text field if I try to create a > record with blank "fname". However if remove the dropdownnlist, it > checks whether fname is present or not. Could anyone tell what I am > doing wrong here? > > Thanks > Silvy Mathews > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
did you try just validates_presence_of :fname without the product and leave the select box in and see if you still get no error ? adam On 2/2/06, Silvy@funmail.com <Silvy@funmail.com> wrote:> Hi Bob, > It did not work either. I do not know what I am doing wrong? > Thanks > Silvy > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Bob Silva > Sent: Thursday, February 02, 2006 3:37 PM > To: rails@lists.rubyonrails.org > Subject: RE: [Rails] Doubts on validation > > Try it with :program_id > > Bob Silva > http://www.railtie.net/ > > > > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > > bounces@lists.rubyonrails.org] On Behalf Of Silvy@funmail.com > > Sent: Thursday, February 02, 2006 11:37 AM > > To: rails@lists.rubyonrails.org > > Subject: [Rails] Doubts on validation > > > > Hi All, > > View > > ******** > > <tr> > > <td><b>Student: </b></td> > > <td><%= text_field "student", "fname", "size" => 40, "maxlength" > > => 40 %></td> > > </tr> > > <tr> > > <td><b>Program: </b></td> > > <td><select id="student_program_id" name="student[program_id]"> > > <%= options_from_collection_for_select @programs, "id", > > "prg_name", @student.program_id %> > > </select> > > </td> > > </tr> > > > > Model > > ******* > > class Student < ActiveRecord::Base > > belongs_to :program > > validates_presence_of :fname, :program end > > > > > > > > When I have the dropdown list with the available programs, the > > application doesn''t validates the text field if I try to create a > > record with blank "fname". However if remove the dropdownnlist, it > > checks whether fname is present or not. Could anyone tell what I am > > doing wrong here? > > > > Thanks > > Silvy Mathews > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi adam, Thanks for responding to my question. I did not write the controller properly. My bad. I did not have the else part. Part of the learning process!! def create begin @student = Student.new(@params[:student]) if @student.save flash[:notice] = ''Student was successfully created.'' redirect_to :action => ''list'' else @offices = Office.find_all @programs = Program.find_all @courses = Course.find_all render :action => ''new'' end rescue flash[''notice''] = ''Item could not be saved.'' redirect_to :action => ''new'' end end Thanks Silvy -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Adam Denenberg Sent: Thursday, February 02, 2006 7:49 PM To: rails@lists.rubyonrails.org Subject: Re: [Rails] Doubts on validation did you try just validates_presence_of :fname without the product and leave the select box in and see if you still get no error ? adam On 2/2/06, Silvy@funmail.com <Silvy@funmail.com> wrote:> Hi Bob, > It did not work either. I do not know what I am doing wrong? > Thanks > Silvy > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Bob Silva > Sent: Thursday, February 02, 2006 3:37 PM > To: rails@lists.rubyonrails.org > Subject: RE: [Rails] Doubts on validation > > Try it with :program_id > > Bob Silva > http://www.railtie.net/ > > > > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > > bounces@lists.rubyonrails.org] On Behalf Of Silvy@funmail.com > > Sent: Thursday, February 02, 2006 11:37 AM > > To: rails@lists.rubyonrails.org > > Subject: [Rails] Doubts on validation > > > > Hi All, > > View > > ******** > > <tr> > > <td><b>Student: </b></td> > > <td><%= text_field "student", "fname", "size" => 40,"maxlength"> > => 40 %></td> > > </tr> > > <tr> > > <td><b>Program: </b></td> > > <td><select id="student_program_id"name="student[program_id]">> > <%= options_from_collection_for_select @programs, "id", > > "prg_name", @student.program_id %> > > </select> > > </td> > > </tr> > > > > Model > > ******* > > class Student < ActiveRecord::Base > > belongs_to :program > > validates_presence_of :fname, :program end > > > > > > > > When I have the dropdown list with the available programs, the > > application doesn''t validates the text field if I try to create a > > record with blank "fname". However if remove the dropdownnlist, it > > checks whether fname is present or not. Could anyone tell what I am > > doing wrong here? > > > > Thanks > > Silvy Mathews > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails