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
Validations in Ruby
Search
Krzysztof Wawer
March 23, 2016
Programming
0
180
Validations in Ruby
Krzysztof Wawer
March 23, 2016
Tweet
Share
More Decks by Krzysztof Wawer
See All by Krzysztof Wawer
The Good Architecture
wafcio
0
610
GIT - Good Practices
wafcio
0
67
Slim Ruby on Rails: Controllers & Middlewares
wafcio
1
160
Dry System
wafcio
0
98
dry-validations
wafcio
0
160
Generating a CSV file with ROM
wafcio
0
300
Trailblazer bez trailblazera
wafcio
0
210
ActiveRecord, DataMapper czy Agregacja encji
wafcio
0
160
Jak (nie) używać Service Object
wafcio
0
200
Other Decks in Programming
See All in Programming
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
500
AI Agent 時代のソフトウェア開発を支える AWS Cloud Development Kit (CDK)
konokenj
5
650
Deep Dive into ~/.claude/projects
hiragram
14
11k
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
980
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
3
790
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
590
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
650
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
2
11k
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
340
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
910
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
670
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
190
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
35
6.7k
How GitHub (no longer) Works
holman
314
140k
GraphQLとの向き合い方2022年版
quramy
49
14k
Agile that works and the tools we love
rasmusluckow
329
21k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
For a Future-Friendly Web
brad_frost
179
9.8k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Code Reviewing Like a Champion
maltzj
524
40k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Transcript
V ALIDATIONS IN Ruby Krzysztof W a wer 23.03.2016 TRUG
ABOUT ME • E-MAIL: krzysztof.w a
[email protected]
• Twitter: https://twitter.com/w
afcio • GITHUB: https://github.com/w afcio
V ALIDATION ???
Ruby on rails ACTIVE MODEL & ACTIVE RECORD Active Model
Active Record
ACTIVE MODEL V ALIDATIONS • acceptance • confirmation • exclusion
• format • inclusion • length • numericality • presence • uniqueness*
UNIQUENESS V ALIDATION
[email protected]
exists ?
[email protected]
exists ? Email
doesn’t exist Email doesn’t exist Create
[email protected]
Create
[email protected]
Created! Created! 1 2
UNIQUENESS V ALIDATION
UNIQUENESS V ALIDATION
[email protected]
exists ?
[email protected]
exists ? Email
doesn’t exist Email doesn’t exist Create
[email protected]
Create
[email protected]
Created! ActiveRecord::RecordNotUnique 1 2
Ruby on Rails • Strong Parameters http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters
STRONG PARAMETERS { name: „John”, surname: „Doe” } { name:
„John” }
STRONG PARAMETERS { name: „John”, surname: „Doe” } ActionController::UnpermittedParameters: found
unpermitted keys: surname ActionController::Parameters.action_on_unpermitted_parameters = :raise
HTTP Requests GET POST GET, POST (JSON) String String String
Integer …
HANAMI http://hanamirb.org https://github.com/hanami •hanami-controller •HANAMI-MODEL •HANAMI-HELPERS •HANAMI-MAILER •HANAMI-VIEW •HANAMI-V ALIDATIONS
•HANAMI-ASSETS •HANAMI-UTILS Luca Guidi
HANAMI-V ALIDATIONS https://github.com/hanami/v alidations#v alidations •ACCEPTANCE •CONFIRMATION •EXCLUSION •INCLUSION •PRESENCE
•FORMAT* •SIZE* •TYPE (Coercions)
HANAMI-V ALIDATIONS • numericality V ALIDATION DoesN’t Exist • „The
framework will treat as V alid any blank attributes, without PRESENCE, for both FORMAT and SIZE predicates.”
DRY https://github.com/dry-rb •DRY-AUTO_INJECT •DRY-COMPONENT •DRY-CONFIGURABLE •DRY-CONSTRUCTOR •DRY-CONTAINER •DRY-EQUALIZER •DRY-INITALIZER •DRY-LOGIC
•DRY-PIPELINE •DRY-TRANSACTION •DRY-TYPES •DRY-V ALIDATION
DRY-V ALIDATION LATEST VERSION: 0.7.0 RELEASE DATE: 16.03.2016 http://dry-rb.org/gems/dry-v alidation/
DRY-V ALIDATION When to use? V ALIDATION OF: • form
params • „GET” params • JSON params • Y AML DOCUMENTS • application configuration • replacement of ActiveRecord / ActiveModel::Validations • replacement of StrongParameters • …
???