class PriceList < ActiveRecord::Base
has_many :prices, :dependent => :destroy
end
和價格:紅寶石 - 訪問parent屬性從子 - 一對多關係
class Price < ActiveRecord::Base
belongs_to :price_list
belongs_to :material
belongs_to :unit
end
現在PRICE_LIST指數我想說明價格列表名稱,而不是ID:
<tbody>
<% @prices.each do |price| %>
<tr>
<td><%= price.price_list.price_list_short_name %></td>
<td><%= price.materials_id %></td>
<td><%= price.units_id %></td>
<td><%= link_to 'Show', price %></td>
<td><%= link_to 'Edit', edit_price_path(price) %></td>
<td><%= link_to 'Destroy', price, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
我在做什麼錯,price.price_list.price_list_short_name
不起作用?
你會得到什麼錯誤?你可以添加'price_list_short_name'方法嗎? –
'PriceList'中有'price_list_short_name'嗎?你能向我們展示異常嗎? –
您在哪個列中存儲price_list的名稱? –