[英]Mongoid has_many / belongs_to has 'undefined method' error
我想在我的 mongoid 模型中使用 has_many/belongs_to。
我已經在其他模型中使用它並且它運行良好,但是在下面的代碼中發生
undefined method `options' for class `Product' error.
楷模 :
class Product
include Mongoid::Document
include Mongoid::Timestamps
has_many :options
field :name, type: String
...
end
class Option
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :product
field :name, type: String
end
控制器 :
class ProductsController < ApplicationController
def index
@products = Product.order(id: :desc)
end
end
我該如何修復錯誤?
您正在使用保留字的選項。 將Option
更改為其他一些詞,例如ProductOption
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.