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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Krzysztof Wawer
March 23, 2016
Programming
0
200
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
650
GIT - Good Practices
wafcio
0
92
Slim Ruby on Rails: Controllers & Middlewares
wafcio
1
190
Dry System
wafcio
0
120
dry-validations
wafcio
0
190
Generating a CSV file with ROM
wafcio
0
340
Trailblazer bez trailblazera
wafcio
0
240
ActiveRecord, DataMapper czy Agregacja encji
wafcio
0
200
Jak (nie) używać Service Object
wafcio
0
220
Other Decks in Programming
See All in Programming
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
660
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
Oxlint JS plugins
kazupon
1
810
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
AI時代の認知負荷との向き合い方
optfit
0
150
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
250
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
dchart: charts from deck markup
ajstarks
3
990
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
51
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
63
Crafting Experiences
bethany
1
48
Designing for Timeless Needs
cassininazir
0
130
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
100
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
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 • …
???