简体   繁体   English

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

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

I'm new in RoR. 我是RoR的新手。 I'm learning models and generating the models for my app and it's associations. 我正在学习模型,并为我的应用及其关联生成模型。 The console generated the error when I tried: 我尝试时,控制台生成了错误:

$ rails console $ 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': wrong number of arguments (given 4, expected 1..3) (ArgumentError) 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)

and more lines of errors but this one is the key I think. 和更多的错误行,但这是我认为的关键。

Solved it, I was writing on the same line different associations which is not correct: 解决了这个问题,我在同一行上写了不同的关联,这是不正确的:

Wrong: 错误:

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

Correct: 正确:

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