Forum: Ruby on Rails Validation fails with select option list

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-02-02 08:36
(Received via mailing list)
I have a form with some text_field and some drop down lists.
<input id="student_fname" name="student[fname]" size="20" value=""
<input id="student_mname" name="student[mname]" size="20" value=""
<input id="student_lname" name="student[lname]" size="20" value=""
 Program:</dt><dd><select id="student_program_id"
 <%= options_from_collection_for_select @programs, "id", "prg_name",
@student.program_id %>

I am not able to use validates_presence_of in the model whenever I am
including this options_from_collection_for_select list. If I remove that
it checks for the presence of the field. Otherwise, it gives me the
following error
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.inject

Extracted source (around line #18):

17: 	<dt>Program:</dt><dd><select id="student_program_id"
18: 	<%= options_from_collection_for_select @programs, "id",
"prg_name", @student.program_id %>
19:     </select>
21:    </dl>

What is the reason for this?

Any help appreciated.
Silvy Mathews
This topic is locked and can not be replied to.