On 15 June 2014 09:29, Ronald Fischer <[email protected]> wrote:
> My solution works, but I wonder if there is a better one.
>
> I have a model (:cards), which has a foreign key :box_id. I am
> interested in the id's of those cards which have a certain box_id.
> Currently I assume that I can easily hold an array of all thos :cards in
> memory (i.e. no cursor needed).

Assuming that you have the relationships setup accordingly (so card
belongs_to box and box has_many cards or something similar) then to
get the cards belonging to a certain box you can just use
@cards = @box.cards
then to get the id of each box in just use box.id

If the above does not make sense then I suggest you work right through
a good tutorial such as railstutorial.org, which is free to use
online, which will show you the basics of Rails.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtzUwcFhgeRgczSFyT21cnDXSSWfUStk5g4KjzoOYicSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to