I'm not sure how to search for this answer, so I'll go ahead and ask it.
In my rails project I have a User model and a foo model. A user can have one or more foo models assigned to it. I have accomplished this by adding
has_many :foo, :through => :user_foo
in my user model.
Now, over in my view, I want to display a list of all foos. Not just the ones that are selected (i will be making these radio buttons, but that's another question). When I try to do this (yes, i'm using haml):
- for foo in @foos
I get this error:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
My assumption is that this is caused because the @foos collection is empty. What is the proper way to get access to this collection within my user view?
** edit **
I think my initial question was a bit confusing. the first issue i'm trying to figure out is how to access a collection of foos from within my user view. the relationship doesn't matter. I just want a list of all foos in the system. not just the ones assigned to the user.