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
160
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
580
GIT - Good Practices
wafcio
0
59
Slim Ruby on Rails: Controllers & Middlewares
wafcio
1
150
Dry System
wafcio
0
92
dry-validations
wafcio
0
150
Generating a CSV file with ROM
wafcio
0
280
Trailblazer bez trailblazera
wafcio
0
200
ActiveRecord, DataMapper czy Agregacja encji
wafcio
0
150
Jak (nie) używać Service Object
wafcio
0
180
Other Decks in Programming
See All in Programming
RubyKaigi Dev Meeting 2025
tenderlove
1
150
プロダクト横断分析に役立つ、事前集計しないサマリーテーブル設計
hanon52_
2
440
これだけは知っておきたいクラス設計の基礎知識 version 2
masuda220
PRO
24
6.4k
Qiita Bash
mercury_dev0517
2
200
Optimizing JRuby 10
headius
0
320
The Nature of Complexity in John Ousterhout’s Philosophy of Software Design
philipschwarz
PRO
0
100
Lambda(Python)の リファクタリングが好きなんです
komakichi
3
200
大LLM時代にこの先生きのこるには-ITエンジニア編
fumiyakume
7
3k
gen_statem - OTP's Unsung Hero
whatyouhide
1
200
海外のアプリで見かけたかっこいいTransitionを真似てみる
shogotakasaki
1
170
The Implementations of Advanced LR Parser Algorithm
junk0612
1
310
Vibe Coding の話をしよう
schroneko
2
830
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Embracing the Ebb and Flow
colly
85
4.6k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Pragmatic Product Professional
lauravandoore
33
6.5k
Facilitating Awesome Meetings
lara
54
6.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
135
33k
Typedesign – Prime Four
hannesfritz
41
2.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.5k
RailsConf 2023
tenderlove
30
1.1k
It's Worth the Effort
3n
184
28k
Transcript
V ALIDATIONS IN Ruby Krzysztof W a wer 23.03.2016 TRUG
ABOUT ME • E-MAIL: krzysztof.w a wer@gmail.com • 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 tester@example.com exists ? tester@example.com exists ? Email
doesn’t exist Email doesn’t exist Create tester@example.com Create tester@example.com Created! Created! 1 2
UNIQUENESS V ALIDATION
UNIQUENESS V ALIDATION tester@example.com exists ? tester@example.com exists ? Email
doesn’t exist Email doesn’t exist Create tester@example.com Create tester@example.com 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 • …
???