繁体   English   中英

在RoR中生成模型时显示错误,模型中的参数数量错误

[英]Error shown when generating models in RoR, wrong number of arguments in model

我是RoR的新手。 我正在学习模型,并为我的应用及其关联生成模型。 我尝试时,控制台生成了错误:

$ rails控制台

mypath.rbenv / versions / 2.3.3 / lib / ruby​​ / gems / 2.3.0 / gems / activerecord-5.1.3 / lib / active_record / associations.rb:1395:in'has_many':错误的参数数量(给定4 ,预期1..3)(ArgumentError)

和更多的错误行,但这是我认为的关键。

解决了这个问题,我在同一行上写了不同的关联,这是不正确的:

错误:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_many :questions, :answers, :comments, :votes
end

正确:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :questions
  has_many :answers
  has_many :comments
  has_many :votes

end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM