Forum: Ruby on Rails Doubts on validation

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.
unknown (Guest)
on 2006-02-02 21:38
(Received via mailing list)
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
Bob S. (Guest)
on 2006-02-03 01:40
(Received via mailing list)
Try it with :program_id

Bob S.
http://www.railtie.net/
This topic is locked and can not be replied to.