0
我試圖訪問該視圖相關聯的模型的方法,但得到一個未定義的方法錯誤未定義方法錯誤(導軌5)
未定義的方法`cpt_code」的步驟:0x007fe7b55518e8
。謝謝你的幫助!
索引視圖:
<% @actuals.each do |actual| %>
<% if actual.procedures.present? %>
<% actual.procedures.each do |procedure| %>
<tr>
<td><%= procedure.cpt_code.id %></td>
<td><%= procedure.description %></td>
</tr>
<% end %>
<% end %>
<% end %>
控制器:
def index
@actuals = Actual.all
end
型號:
class Actual < ApplicationRecord
has_many :actual_procedures, :dependent => :destroy
has_many :procedures, through: :actual_procedures
class ActualProcedure < ApplicationRecord
belongs_to :procedure
belongs_to :actual
end
class Procedure < ApplicationRecord
has_many :actual_procedures
has_many :actuals, through: :actual_procedures
end
class CptCode < ApplicationRecord
has_one :procedure
在程序模式:
create_table "procedures", force: :cascade do |t|
t.bigint "cpt_code_id"
t.string "code"
t.string "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["cpt_code_id"], name: "index_procedures_on_cpt_code_id"
end