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
570
GIT - Good Practices
wafcio
0
54
Slim Ruby on Rails: Controllers & Middlewares
wafcio
1
140
Dry System
wafcio
0
89
dry-validations
wafcio
0
150
Generating a CSV file with ROM
wafcio
0
270
Trailblazer bez trailblazera
wafcio
0
190
ActiveRecord, DataMapper czy Agregacja encji
wafcio
0
140
Jak (nie) używać Service Object
wafcio
0
170
Other Decks in Programming
See All in Programming
Kotlinの開発でも AIをいい感じに使いたい / Making the Most of AI in Kotlin Development
kohii00
3
280
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
1
210
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
190
Domain-Driven Transformation
hschwentner
2
1.9k
『品質』という言葉が嫌いな理由
korimu
0
180
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
210
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
920
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
900
コードを読んで理解するko build
bells17
1
100
Rubyで始める関数型ドメインモデリング
shogo_tksk
0
130
昭和の職場からアジャイルの世界へ
kumagoro95
1
420
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
110
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
KATA
mclloyd
29
14k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
Typedesign – Prime Four
hannesfritz
40
2.5k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Automating Front-end Workflow
addyosmani
1368
200k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Gamification - CAS2011
davidbonilla
80
5.1k
Building Adaptive Systems
keathley
40
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 • …
???