New to Ruby on Rails so please be patient.
I have two tables policies and standards
Policies has id, and PolicyName fields
Standards has id, StandardName and ParentPolicyId fields.
Each tale has a primary key on id and Standards has a foreign key on
ParentPolicyId referencing Policies.id.
My model is as follws:-
class Standard < ActiveRecord::Base
class Policies < ActiveRecord::Base
I am simply trying to list policies and all their related standards
using the following controller code.
@policies = Policy.find_all
…and the following rhtml code:-
<% @policies.each do |policy| %>
I just cant understand the rhtml code that I should use to reference a
field in standards via its foreign key relationsip to policies. I
thought that the foreign key would set up the required links such that I
can just refer to the field in the standards table via the
policy.standards.StandardName syntax. However I get errors about
.standards not being a method of polcies.
I appreciate this is probably a ‘day one’ misunderstanding but help out
an old coder trying new things!..What should the rhtml code be or is
my error elsewhere?
Thanks in advance for any help.