Barney <bsperlin@...> writes:
>
> And a relevant section of index.html.erb is:
> <%= @people.each do |person| %>
> <tr>
> ...
> <td><%= person.zip_code %></td>
> <td><%= person.skill_set %></td>
> <td><%= WHAT GOES HERE TO BE ABLE TO PRINT THE "position" FIELD OF
> THE employee_infos TABLE? WHAT CHANGES SHOULD BE MADE TO THE ABOVE?
If I am reading this right:
<td><%= person.employee_info.position %></td>
Note: this will trigger a database query to match the record in employee_info
with the person's ID. Your @employee_infos variable is not being touched.
You really want eager load:
@people = Person.all.include(:employee_info)
>
> A second point was made about not having SQL statements in the
> controller (which I have done) so what is the alternative? What pages
> can I go to to see some examples of the right way?
The seminal blog post was this http://weblog.jamisbuck.org/2006/10/18/skinny-
controller-fat-model
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment