ArgumentError (wrong number of arguments (given 0, expected 1)) error message

Introduction

When I did "rails s", I got an error about the destroy method, and I had a hard time not knowing where to fix it, so I will write it as a record.

Error message

persistence.rb:325:in `destroy': wrong number of arguments (given 0, expected 1) (ArgumentError)

Cause

There was a problem with how to write in the model.

user.rb


class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  attachment :profile_image
  has_many :tasks, dependent: destroy
end

solution

It's very simple, but I solved it by fixing the description of the file in the model.

user.rb


class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  attachment :profile_image
  has_many :tasks, dependent: :destroy
end

Reference article https://teratail.com/questions/244096

Recommended Posts

ArgumentError (wrong number of arguments (given 0, expected 1)) error message
wrong number of arguments (given 1, expected 0)
[Rails] Sign-up function using devise error number of arguments (given 0, expected 1)
[Rails] How to resolve wrong number of arguments (given 2, expected 0..1) of user_id
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
[RSpec] ArgumentError: wrong number of arguments If you get an error, you may have to worry about variable naming.
What to do if you get a wrong number of arguments error in binding.pry
About the error message Invalid redeclaration of'***'
[Rails] Japanese localization of validation error message ~ ja.yml ~