簡體   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