Re: [Rails] Re: Associations join
On 20 June 2012 09:32, Timen E. <lists@ruby-forum.com> wrote:
> Still got one(Hopefuly last for now) question, guys.
>
> I've got the above data now and i can access my cards through users that
> are joined by the cardlevel. I'm trying to loop through all the cards a
> user has as such:
> <% @user.cards.each do |c| %>
> <%= c.name %><br>
> <% end %>
>
> And this works great. However i'd like to get some extra info about this
> card from my cardlevel array, but i can't seem to access it like this. I
> can however loop it in a seperate each, but i don't want that obviously.
You have not explained well what you are trying to do, but possibly
you want to loop through the cardlevels instead of the cards, then for
each cardlevel you can obtain the card aswell as the other data, so
something like
<% @user.cardlevels.each do |cl| %>
<%= cl.card.name %><br>
<%= cl.other_data %>
<% end %>
You might need to check for cl.card nil though.
Colin
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home