2023-10-10 Rails enum validataion
ちょうど Rails enum でなんで強制ArgumentErrorやねーんってなってたところなのでこの変更はありがたい » Make enums validatable without raising error by mechnicov · Pull Request #49100 · rails/rails https://t.co/jeBFkfAD3n
— toshimaru (@toshimaru_e) September 7, 2023
Rails enum validataion
class Conversation < ActiveRecord::Base
enum :status, [ :active, :archived ], validate: true
end
conversation = Conversation.new
conversation.status = :unknown
conversation.valid? # => false
conversation.status = nil
conversation.valid? # => false
conversation.status = :active
conversation.valid? # => true