Topic: Showing associated objects?
I'm new to the rails (and the entire web application) development scene. I've been working on building a rudimentary job tracking database and I am running into difficulties with showing associated objects.
Jobs have a has_many relationship to Samples, withsamples having a belongs_to relationship with jobs. All of the scaffolding and associations work, but I would like to be able to generate a table of the samples that belong to a job in the view method.
So far, I have done this in the jobs_controller:
@job = Job.find(params[:id], :include => [:samples])
Which presumably tells it to seek out associated samples for the job being viewed. That's pretty much where I get stuck. I've been attempting to generate the table this way in the show.rhtml file:
<table border = "1">
<% for samples in @job %>
<td><%= sample.description %></td>
<td><%= sample.quantity %></td>
<% end %>
But... Well, it doesn't appreciate it. Everything else seems to be working in terms of the associations. Samples can be associated with jobs and in the case of the test data I am using, there is a sample associated with the job I'm attempting to show. Any help or suggestions would be greatly appreciated.