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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Butler 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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
%></td>
<% end %>
Can anyone help?
Johnny B
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---