Name of Foreign Key record in rails view -
how find record name of foreign key in rails view?
for example, have view lists following:
<% @cycles.each |cycle| %> <tr> <td><%= cycle.name %></td> <td><%= cycle.program.try(:name) %></td> <td><%= cycle.previous_cycle_id %></td> <td><%= cycle.next_cycle_id %></td>
for cycle.previous_cycle_id
, instead of printing out 1 example, want print out name of cycle, cycle one.
thanks help!
unless have name of previous cycle stored in current cycle (or somewhere else in memory), you'll have query database find name. in case
<%= cycle.find(cycle.previous_cycle_id).name %>
Comments
Post a Comment