Postgres DB テーブルの値が一意かどうかを if ステートメントを使用して確認したいと考えています。ユニークな場合は何かを行い、ユニークでない場合は別のことを行います。Ruby on Rails での疑似コードは次のようになります。
if validates_uniqueness_of :number == "true"
puts "this value is unique and should be added to the DB"
else
puts "this value is not unique and should not be added to the DB"
end
このタイプのロジックをモデルまたはコントローラーに実装できますか? はいの場合、どちらがより良い方法ですか? いいえの場合、代わりに何をすべきですか? また、構文はこのようなものにどのように見えるでしょうか?
みんなありがとう!