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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
nakayama-bird
November 27, 2025
Programming
97
0
Share
Enumのvalidateオプションで しくじった話
2025.11.27 Ruby on Railsのテーブル設計とトランザクション処理 LT Night
nakayama-bird
November 27, 2025
More Decks by nakayama-bird
See All by nakayama-bird
非同期×イベント分離でMtgを短縮!
nakayama__bird
1
320
はじめてのRailsの ソースコードリーディング
nakayama__bird
1
72
Other Decks in Programming
See All in Programming
TiDBのアーキテクチャから学ぶ分散システム入門 〜MySQL互換のNewSQLは何を解決するのか〜 / tidb-architecture-study
dznbk
1
170
実用!Hono RPC2026
yodaka
2
200
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
140
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
1
320
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
3
130
Don't Prompt Harder, Structure Better
kitasuke
0
750
アーキテクチャモダナイゼーションとは何か
nwiizo
17
5.1k
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
350
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
260
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
910
実践CRDT
tamadeveloper
0
550
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
220
The Mindset for Success: Future Career Progression
greggifford
PRO
0
310
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
340
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
[SF Ruby Conf 2025] Rails X
palkan
2
960
The Limits of Empathy - UXLibs8
cassininazir
1
300
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Mobile First: as difficult as doing things right
swwweet
225
10k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
140
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
98
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