Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Enumのvalidateオプションで しくじった話
Search
nakayama-bird
November 27, 2025
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
460
はじめてのRailsの ソースコードリーディング
nakayama__bird
1
90
Other Decks in Programming
See All in Programming
Workers Cache を知る
syumai
0
370
すこし踏み込む CancellationToken
htkym
2
1.7k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
500
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
220
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
220
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
720
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
1
5.4M
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
Typedesign – Prime Four
hannesfritz
42
3.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Making the Leap to Tech Lead
cromwellryan
135
10k
Code Review Best Practice
trishagee
74
20k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
Documentation Writing (for coders)
carmenintech
77
5.6k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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