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
150
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
550
GIT - Good Practices
wafcio
0
49
Slim Ruby on Rails: Controllers & Middlewares
wafcio
1
130
Dry System
wafcio
0
89
dry-validations
wafcio
0
140
Generating a CSV file with ROM
wafcio
0
250
Trailblazer bez trailblazera
wafcio
0
180
ActiveRecord, DataMapper czy Agregacja encji
wafcio
0
120
Jak (nie) używać Service Object
wafcio
0
160
Other Decks in Programming
See All in Programming
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
660
Symfony Mapper Component
soyuka
2
730
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
3
1.4k
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
선언형 UI에서의 상태관리
l2hyunwoo
0
140
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
快速入門可觀測性
blueswen
0
330
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
CSC305 Lecture 25
javiergs
PRO
0
130
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1366
200k
Bash Introduction
62gerente
608
210k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.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 • …
???