Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
The Active Model
Search
Luis Alfredo Lorenzo
August 25, 2016
Technology
28
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Active Model
A brief introduction with examples to Rails Active Model library.
Luis Alfredo Lorenzo
August 25, 2016
More Decks by Luis Alfredo Lorenzo
See All by Luis Alfredo Lorenzo
Getting started with factory_girl in 7 minutes
babasbot
0
42
Other Decks in Technology
See All in Technology
Refining Active Record
shugo
0
160
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
140
Running Kotlin + Quarkus with Lambda
nealle
1
3.8k
re:Invent初参加で変わったこと、2回目にやってみたいこと(JAWS-UG彩の国埼玉 #12)
mhrtech
2
230
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
350
How to Design Configuration for Rails Applications
willnet
1
810
オントロジーって 結局なにもの? AI エージェントに「意味」を渡す知識設計の話
greenmidori
0
210
Claude の新機能を、 出た日に触って社内に届けるまで
rfdnxbro
1
180
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
今さら理解するウェブフォントver.2026
takanorip
3
830
Featured
See All Featured
BBQ
matthewcrist
90
10k
From π to Pie charts
rasagy
1
400
Everyday Curiosity
cassininazir
0
350
Balancing Empowerment & Direction
lara
6
1.3k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Deep Space Network (abreviated)
tonyrice
0
370
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
520
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
THE ACTIVE MODEL THE ACTIVE MODEL THE ACTIVE MODEL THE
ACTIVE MODEL THE ACTIvE MODEL THE ACTIVE MODEL_ POR: LUIS ALFREDO LORENZO A.K.A BABASBOT
BABASBOT
None
github.com/mxabierto
None
None
ACTIVE RECORD ACTIVE ReCORD ACTIVE RECCORD ACTIVE RECORD ACTIvE RECORD
ACTIVE RECORD
ACTIVE REDCORD IS THE M IN MVC
OBJECT Relational Mapping SYSTEM RAILS
thE Active Record pattern
ACTIVE MODEL ACTIVE MODEL ACTIVE MODEL ACTIVE MODEL ACTIvE MODEL
ACTIVE MODEL_
_WHY Active MODEL?
ActiveModel::AttributeMethods
class Pokemon include ActiveModel::AttributeMethods attr_accessor :hp attribute_method_prefix 'clear_' define_attribute_methods :hp
def clear_attribute(attr) send("#{attr}=", 0) end end
class Pokemon include ActiveModel::AttributeMethods attr_accessor :level attribute_method_suffix '_highest?' define_attribute_methods :level
private def attribute_highest?(attribute) send(attribute) >= 100 end end
ActiveModel::Callbacks
class Pokemon extend ActiveModel::Callbacks attr_accessor :level, :name define_model_callbacks :level_up around_level_up
:evolve def level_up run_callbacks(:level_up) do self.level += 1 end end def evolve puts 'What? #{name} is evolving!' yield puts ‘#{name} has evolved into Raichu.' end end
ActiveModel::DIRTY
class Pokemon include ActiveModel::Dirty define_attribute_methods :level def level @level end
def level=(val) level_will_change! unless val == @level @level = val end def save changes_applied end end
ActiveModel::VALIDATIONS
class Pokemon include ActiveModel::Validations attr_accessor :name validates :name, presence: true
end
ActiveModel::NAMING
class Pokemon extend ActiveModel::Naming end
ActiveModel::MODEL
class Pokemon include ActiveModel::Model attr_accessor :name, :level, :hp validates :name,
:level, :hp, presence: true end
None
THE END?