I have two tables, Beacon belongs to Category and Category has many beacons, in beacon table, I add a foreign key: category_id, but when i want display in table, i need the category_name in the category table, now I use a stupid way as following:
...
<% @beacons.each do |beacon| %>
<tr>
<td><%= beacon.beacon_uuid %></td>
<% @category_name = Category.find(beacon.category_id).category_name %>
<td><%= @category_name %></td>
...
but when beacon data get bigger, request get bigger, how to change my code to defence this stupid question?can someone give me some suggestion or reference? Thanks a lot.