我有兩個對象:協會 - 外鍵
create_table "conditions", force: true do |t|
t.string "name"
t.integer "condition_category_id"
end
create_table "condition_categories", force: true do |t|
t.string "name"
end
我想列出我與另一列條件類別名稱的條件。然而,因爲我用下劃線命名它,所以我對如何正確設置關聯感到困惑。我注意到這個模型被重寫爲ConditionCategory,但是我仍然無法正常工作。
這裏是我的條件
class Condition < ActiveRecord::Base
belongs_to :category, class_name: 'ConditionCategory'
end
而且在我的視圖模型
<td><%= condition.category.name %></td>
相對較新的軌道,所以任何的幫助深表感謝