1

Topic: Showing a specific attribute from a belongs_to on a table

For some reason this removed a lot of what I wrote.

Basically I have a User, Car, and Suspension Models. Suspension belongs_to car, Car belongs_to User. When a suspension is made, it is assigned to one of the users cars. On the Car/index page I have a table of the users cars. I want one of the columns to show the bolt pattern (suspension attribute) on the table. I'm really stuck with it.

Last edited by 71 (2012-09-11 19:20:07)

Re: Showing a specific attribute from a belongs_to on a table

You can go through models that have a relationship set-up in the models such as if I have a user and centre tables where I want to get the name of the centre the user belongs to I would do.

<% for user in @users %>
  <%= user.centre.name %>
<% end %>

You can use the same process

<% for user in @users %>
  <%= user.car.bolt_pattern %>
<% end %>