Hi. I am new to rails and am hoping someone can help me understand why I am getting a certain error. I have gone through the Agile Web Development Book and am now trying to build a basic app (job board) to try something "real world."
I have a form where I collect the job details. In the form is a select statement which pulls categories from the DB. The categories are in an instance variable that I create in the index method. When I load the form, the categories are loaded correctly. However, then I added validation, and when a validator kicks, I get a NoMethodError (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.inject).
It points me to the select statement in my form as the culprit. So, it seems that the instance variable is not populated, after the error, when its part of the index method. I think I confirmed this by putting the instance variable inline, before the select statement, in the form. Then everything worked as expected.
I really am just trying to learn what I am doing wrong and why that isn't filling the instance variable with the categories. Any education is appreciated!!
Thanks
Josh
Here is relevant code: