简体   繁体   中英

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

I'm new in 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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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