Foreign keys not displayed for user input in create function

Newbie to Ruby - would appreciate it enormously if somebody could help
me with this.

In my create function, for a specific table, my foreign keys in that
table are not visible for selection. However, at the time of writing
to the database, they take one or the other values on these foreing
keys. I carried out the validates_presence_of on these foreign keys
and that started generating errors but it still did not show the
foreign keys.


Exam |---------< Exam_Subjects

--------| Subjects
Exam_id Exam_id (foreign-
key) Subject_id
Exam_Name Subject_id (foreign-
key) Subject_Name


After generating the scaffolding, when I go to exam_subject/create
screen, it only displays text-boxes to input Percent_of_questions and
Difficulty_level_of_subjects. Its doesnt show Subject_id or Exam_id
for input and takes default values to fill it.

What I need is drop downs for Exam_Name and Subject_Name.

I tried using the validates_presence_of Exam_id which actually
resulted in generating an error but still no way of beinbg able to
show the name fields for input.

I was going to write a code but think there must be some ruby method I
can use to show all foreign keys for input? Is there one? Am I missing

Hi Sky,

You need to add something like this to your form assuming you are
using form_for:-

<%=‘exam_id’, @exams.collect {|exam| [, ]})

You’ll initialise exams instance variable in your controller (@exams =
Exam.find(:all)). You need to do something similar for the the Subject
drop down. I hope that answers your question?