Help for newbie please!
I have two tables: controls and programs.
controls has_many :programs
Programs belongs_to :control
Controls has id, controlname
Programs has, apart from it’s own id, two fields ctl1_id and ctl2_id.
These represent two controls that the program relates to.
Foreign keys are set on program table columns ctl1_id and ctl2_id back
to the id field on the control table.
So when I list the program table using
<% @programs.each do |array| %>
…everything is fine.
But when I list the programs row I want to actually show the controlname
from controls table rather than the ctl1_id and ctl2_id values from the
programs row. For this I use the following code:-
<% @programs.each do |array| %>
I expect the link via the foreign keys and the models relationships to
give me what I need but I am obviously missing something because I get
this:-.
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.control
Extracted source (around line #56):
53:
54:
55:
56: <%= array.control.controlname %>
I have checked out the cookbook application code and cant see where I am
misunderstanding.
Any help gratefully received.
Thanks
I can see that