Alyanna Alyanna - 1 year ago 73
Ruby Question

How do I match ids?

I have 3 controllers which are 'client_workouts', 'client' and 'trainer'. In the client_workouts controller I want to have a link which directs you to the 'client/:id' page. But it doesn't seem to work?

<td><%= link_to client_workout.client_name, 'client' %></td>
<td><%= link_to client_workout.trainer, 'trainer' %></td>
<td><%= client_workout.duration_mins %></td>
<td><%= client_workout.date_of_workout %></td>
<td><%= client_workout.paid_amount %></td>
<td><%= link_to 'Show', client_workout %></td>
<td><%= link_to 'Edit', edit_client_workout_path(client_workout) %></td>
<td><%= link_to 'Destroy', client_workout, method: :delete, data: { confirm: 'Are you sure?' } %></td>

Do I have to match the id's???

Answer Source

If you want to go client/:id i.e. show action

you need to send client id as a parameter

   <td><%= link_to client_workout.client_name, client_path( %></td>