LoginSignup
0
0

More than 3 years have passed since last update.

like.rb

Posted at

class Like < ApplicationRecord
validates :user_id,{presence: true}
validates :post_id,{presence: true}
end
//バリデーションを追加する
いいねのデータは、user_idとpost_idの両方が常に存在していないと不完全なデータとなってしまいますので、最初にバリデーションを追加しておきましょう。user_idとpost_idのそれぞれに、値が存在していることをチェックする「presence: true」のバリデーションを追加します。
両方存在しないと不完全なデータになってしまう

0
0
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
0
0