Hi everybody!! I''m newbie in Rails and Ruby so I need a bit of help!!!. My problem is I try to show an attribute from a has_many object. I think is better gone through the code, so here we are: <% for subject_specification in @subject_specifications %> <tr> <td><%= subject_specification[:name] %></td> <td> <%= subject_specification.subjects.????? %> </td> </tr> <%# breakpoint %> <% end %> (SubjectSpecification has many Subjects and Subjects belongs to SubjectSpecification) The matter is that I need to show subjects_specification.subjects.year (year is char(1)), which is an attribute of subjects. If I run the breakpointer, I try to do something like this (extracted from The Pragmatic Programmers Book): irb(main):001:0> pr = Product.find(:first) => #<Product:0x248acd0 @attributes={"image_url"=>"/images/sk..." irb(main):002:0> pr.price => 29.95 irb(main):003:0> pr.price = 34.95 => 34.95 irb(main):004:0> pr.save => true which I guess it''s similar what I need but it doesnt work. Thank you very much in advance. Rosi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Manuel González Noriega
2005-Sep-22 13:14 UTC
Re: Show an attribute from a has_many object
> > <% for subject_specification in @subject_specifications %> > <tr> > <td><%= subject_specification[:name] %></td> > <td> > <%= subject_specification.subjects.????? %> > </td> > </tr> > <%# breakpoint %> > <% end %> > > (SubjectSpecification has many Subjects and Subjects belongs to > SubjectSpecification)I''m probably much of a newbie than you are, but I''l dare to say that subjects is an array and you need to iterate through it: subject_specification.subjects.each do | subject | <%= subject.year %> end Chances are I''m wrong but still... :-) Also, I presume from your name you speak Spanish. May I point you to the spanish-language RoR mailing list? http://lists.simplelogica.net/mailman/listinfo/ror-es -- Manuel a veces :) a veces :( pero siempre trabajando duro para Simplelógica: apariencia, experiencia y comunicación en la web. http://simplelogica.net # (+34) 985 22 12 65 ¡Ah! y escribiendo en Logicola: http://simplelogica.net/logicola/