Skip to content

Commit edc41e6

Browse files
committed
feat: News モデルにバリデーションを追加
バリデーション内容: ✅ title: 必須項目 ✅ url: 必須項目 + 重複禁止 + HTTP/HTTPS形式チェック ✅ published_at: 必須項目 目的: - データの整合性を保証 - 重複URLの防止
1 parent 3a1bece commit edc41e6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

app/models/news.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
class News < ApplicationRecord
22
scope :recent, -> { order(published_at: :desc) }
3+
4+
validates :title, presence: true
5+
validates :url, presence: true,
6+
uniqueness: true,
7+
format: { with: /\Ahttps?:\/\/.*\z/i }
8+
validates :published_at, presence: true
39
end

0 commit comments

Comments
 (0)