Hi,
I cant seem to find the answer to this anywhere so any help/advice is
appreciated.
Each project has one risk and a risk has a number of has/one belongs to
assocations. So what i want to do is in my code loop through all the
associations for a risk and display some field information from each as
they are pretty similar. So somehting like
<% for model_association in project.risks %>
<%= model_association.model_name %>
<%= model_or_assocation.name %>
<% end %>
Each association to risk has a filed called name present which i would
like displayed
Is this possible or whats the best way to something like this?
Johnny B
Ihad to di a bit deeper but found the following in the API
http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/ClassMethods.html
http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/MacroReflection.html
reflect_on_all_associations looks like it will do the job
John B
John B. wrote:
Hi,
I cant seem to find the answer to this anywhere so any help/advice is
appreciated.
Each project has one risk and a risk has a number of has/one belongs to
assocations. So what i want to do is in my code loop through all the
associations for a risk and display some field information from each as
they are pretty similar. So somehting like
<% for model_association in project.risks %>
<%= model_association.model_name %>
<%= model_or_assocation.name %>
<% end %>
Each association to risk has a filed called name present which i would
like displayed
Is this possible or whats the best way to something like this?
Johnny B
How can i actually i get the value of the object relationship, so the
code below will output the class name of each association for the risk
which is a start. So what i want is to display a field value belonging
to the association
<% for association in @project.risk.class.reflect_on_all_associations %>
<%= association.name %>#This will print out the name
#So i need to get the association model name where the qoutes are
below
<%= @project.material_risk.“association.name”.field_value %>
<% end %>
Can anyone help?
Johnny B