Hello all,
This is my first time setting up associations in Rails. A User :has_many
Jobs, and a Job :belongs_to a User.
Take a peak at this code and tell me what you think. For some reason,
when I pull these jobs and try to iterate through to show a list of Jobs
posted by a User, I get a strange error with the "each" function.
Since you are accessing jobs through the @user instance, you don't
need to specify the "find by user id". Rails already knows to only
find jobs associated with that user.
You can just do this: @user.jobs
And this: @user.jobs each do | job |
Make sure you have "has_many :jobs" in your User model. Didn't see
that posted in your code.
Also, might not be a bad idea to familiarize yourself with the Rails
Association documentation. It will answer a lot of questions like
this.