Forum: Ruby on Rails Validation fails with select option list

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.
5190273ecab4b93b2d4e7529dcc1f7c6?d=identicon&s=25 unknown (Guest)
on 2006-02-02 07: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=""
type="text">
<input id="student_mname" name="student[mname]" size="20" value=""
type="text">
<input id="student_lname" name="student[lname]" size="20" value=""
type="text">
 Program:</dt><dd><select id="student_program_id"
name="student[program_id]">
 <%= options_from_collection_for_select @programs, "id", "prg_name",
@student.program_id %>
</select>

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"
name="student[program_id]">
18: 	<%= options_from_collection_for_select @programs, "id",
"prg_name", @student.program_id %>
19:     </select>
20:
21:    </dl>

What is the reason for this?

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