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
440
はじめてのRailsの ソースコードリーディング
nakayama__bird
1
89
Other Decks in Programming
See All in Programming
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.9k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
200
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.5k
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
470
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
490
アクセシビリティから考える情報設計
high_g_engineer
0
380
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
330
AHC070解法紹介
eijirou
0
120
自分的「カンファレンスの楽しみ方」
syumai
0
200
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
170
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
190
スマート反転とウェブアクセシビリティ
camiha
0
210
Featured
See All Featured
It's Worth the Effort
3n
188
29k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
330
Mind Mapping
helmedeiros
1
360
Tell your own story through comics
letsgokoyo
1
1.1k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
490
Everyday Curiosity
cassininazir
0
320
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
420
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Prompt Engineering for Job Search
mfonobong
0
450
Test your architecture with Archunit
thirion
2
2.4k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
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