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



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

$ 导轨控制台

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( (参数错误(

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

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

错:

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

最新更新