Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Enumのvalidateオプションで しくじった話
Search
nakayama-bird
November 27, 2025
Programming
0
96
Enumのvalidateオプションで しくじった話
2025.11.27 Ruby on Railsのテーブル設計とトランザクション処理 LT Night
nakayama-bird
November 27, 2025
Tweet
Share
More Decks by nakayama-bird
See All by nakayama-bird
非同期×イベント分離でMtgを短縮!
nakayama__bird
1
300
はじめてのRailsの ソースコードリーディング
nakayama__bird
1
70
Other Decks in Programming
See All in Programming
The free-lunch guide to idea circularity
hollycummins
0
380
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
480
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
280
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
1.4k
Claude Code Skill入門
mayahoney
0
440
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
1.2k
20260320登壇資料
pharct
0
130
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
170
20260315 AWSなんもわからん🥲
chiilog
2
180
Windows on Ryzen and I
seosoft
0
410
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
150
Nostalgia Meets Technology: Super Mario with TypeScript
manfredsteyer
PRO
0
110
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Scaling GitHub
holman
464
140k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
310
Unsuck your backbone
ammeep
672
58k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
150
Mobile First: as difficult as doing things right
swwweet
225
10k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
990
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Building the Perfect Custom Keyboard
takai
2
720
Transcript
© Findy Inc. 2025.11.27 Ruby on Railsのテーブル設計とトランザクション処理 LT Night Enumのvalidateオプションで
しくじった話 1 ファインディ株式会社 Team+開発部 中嶋 ひかる
© Findy Inc. 2 ⾃⼰紹介 中嶋 ひかる @nakayama__bird 経歴 前職:公務員(税関職員🛃)
オンラインのプログラミングスクールを経て、 2024/12にファインディに⼊社 RailsメインでFindy Team+の開発してます RubyとRails歴は2年くらいです
© Findy Inc. Railsのenumって便利ですよね 3
© Findy Inc. 4 こんな感じで定義をすれば Userの権限をenumで定義する(⼀部抜粋)
© Findy Inc. 5 Rubyっぽいメソッドで問い合わせできる Predicate Methods(述語メソッド)= 末尾に疑問符?がつき、真偽値(boolean値)を返すメソッド
© Findy Inc. 6 scopeで絞り込みできる 実質的に User.where(role: :admin) と同じ絞り込みが直感的に書ける
© Findy Inc. enumのvalidate: trueについて 7
© Findy Inc. 8 enumのvalidateオプションについて ‧Rails 7.1で追加された https://railsguides.jp/7_1_release_notes.html ‧enumに、validate: trueのオプションを設定すると、enumにある値以外を受け取った場合に、バリデー
ションのエラーとなるようになった https://github.com/rails/rails/pull/49100 ‧デフォルトはfalseで、その場合はArgument Errorが発⽣する
© Findy Inc. enumのvalidateオプションで しくじった話 9
© Findy Inc. 10 外部APIからのレスポンスで列挙型のプロパティがあった ‧ドキュメントで列挙されている内容をenumで定義 ‧validate: trueで設定した propertyには下記のようなも のがあります
‧status ‧title ‧label …
© Findy Inc. 11 実際に取得処理をしたら別のプロパティがあった ‧バリデーションエラーが発⽣ ‧ドキュメントには掲載されていないpropertyが複数あった ‧エラーになったプロパティを確認しenumに追加した ‧今後も新たなプロパティの追加があると考えvalidate: trueのオプションを外した
© Findy Inc. 12 時は流れてリリース後 ‧Argument Errorエラーになっている!! ‧新しくemailというpropertyが追加された+validate: trueのオプションを外したことでぱっと⾒でなんのエ ラーかわからない状況になってしまった
‧⼀時対応としてpropertyのenumにemailを追加することで対応
© Findy Inc. 13 反省点、今後の⽅針、まとめ ‧validate: trueの挙動を正しく理解せず変更を⾏ってしまった=>いずれにせよエラーにはなるがバリデー ションエラーの⽅が原因把握しやすかった ‧そもそもenumではなくしてしまうという⽅針もあったが、プロダクトとしてそのTypeに対応するしない の判断を⾏うために列挙型は維持したい
‧取得時、enumに定義されていないものがあった場合にはunknownで⼀旦インポート処理してデータを確 認=>enumに追加が流れとして良さそう?という話になっている ‧外部APIの列挙型のデータの扱い⽅について気になるのでお話し聞きたいです!
© Findy Inc. ご清聴いただきありがとうございました! 14