我有三种模式:用户、产品和订单。关联如下:
用户(卖家)有许多产品
用户(买家)有许多订单
订单有一个产品
订单有一个用户(买家)
一个产品有一个用户(卖家)
产品有一个订单
现在在产品模型中有一个与用户的关联:
belongs_to :seller, class_name: "User", foreign_key: "seller_id"
在用于添加新产品的products_controller中,将其链接到用户:
def create
@product = current_user.products.create(product_params)
....
在数据库中,外键也已重命名为“seller_id”。
当current_user。产品线被称为响应失败
ActiveRecord::UnknownAttributeError (unknown attribute 'user_id' for Product.):
app/controllers/products_controller.rb:23:in `create'
我不确定如何将current_user-to-products关联更改为使用此seller_id密钥。任何帮助都将不胜感激,谢谢。