1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ArgumentError(wrong number of arguments (given 0, expected 1))のエラーメッセージ

Posted at

はじめに

「rails s」をしたときにdestroyメソッドに関するエラーが出て、どこを直せば良いのかよくわからずに苦労したので、記録として書きます。

エラーメッセージ

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

###原因
モデルの中の記述の仕方に問題がありました。

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

###解決策
すごく単純ですが、モデルの中のファイルの記述を治してあげれば解決しました。

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

参考記事
https://teratail.com/questions/244096

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?