brain has turned to sludge, can't figure out how to do this
I have two classes that are related in rails, say Bucket and Water
A bucket has_many :water, and water belongs_to :bucket
The bucket has a name and item number. The water has the item number of the bucket it belongs to.
When I'm putting out the info on water in, say, an @water.each loop, how do I get ruby to output the name of the bucket the water belongs to?
thinking about it from a sql perspective, i would think it'd be something like '@bucket.name where bucket.item_number == water.item_number' but I can't think that would work
edit
so I tried this in the waters view:
Code:
@waters.each do |water|
@buckets.each { |bucket| bucket.name if bucket.item_number == water.item_number }
end
but it complained that 'undefined method `each' for nil:NilClass' (referring to the buckets line). Tried to add buckets as a resource for the water resource in routes, but that didn't help =-/
Last edited by Loki; 01-25-2016 at 03:31 PM.