Skip to content

Instantly share code, notes, and snippets.

View hamajyotan's full-sized avatar

SAKAGUCHI Takashi hamajyotan

View GitHub Profile
@hamajyotan
hamajyotan / auto_presence_validation.rb
Created September 13, 2017 00:31
NOT NULL 制約の定義されている列に対し、自動的に presence バリデーションを付与
# frozen_string_literal: true
# NOT NULL 制約の定義されている列に対し、自動的に presence バリデーションを付与します
#
module AutoPresenceValidation
extend ActiveSupport::Concern
included do
ignore_types = %i[boolean]
@hamajyotan
hamajyotan / hoge.rb
Created May 24, 2019 00:06
activerecord validation error i18n
# app/models/hoge.rb
class Hoge < ApplicationRecord
validates :foo, presence: true
validates :bar, presence: true
validates :foo, uniqueness: { scope: [:bar] }
end