a blink into the rails magic
DESCRIPTION
My presentation at Athens Digital Week '09TRANSCRIPT
![Page 1: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/1.jpg)
A BLINK INTO THE “RAILS MAGIC”
The meta-programming in Rails / Rails as a code generator
![Page 3: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/3.jpg)
The “classic” rails ingredients
MVCDRYCOC…
![Page 4: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/4.jpg)
Not for today…
MVCDRYCOC…
![Page 5: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/5.jpg)
Rails as a code generator
![Page 6: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/6.jpg)
PART I :
100% Static
![Page 7: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/7.jpg)
The directory structure
![Page 8: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/8.jpg)
Models + Tests
![Page 9: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/9.jpg)
Controllers / views + tests
![Page 10: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/10.jpg)
Resources (the whole set)
![Page 11: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/11.jpg)
Even with *implemented* views & controllers (a.k.a. “scaffolds”)
![Page 12: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/12.jpg)
![Page 13: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/13.jpg)
![Page 14: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/14.jpg)
![Page 15: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/15.jpg)
![Page 16: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/16.jpg)
![Page 17: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/17.jpg)
Static(*) API
![Page 18: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/18.jpg)
![Page 19: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/19.jpg)
![Page 20: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/20.jpg)
Nothing special so far…
![Page 21: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/21.jpg)
PART II :
100% On-the-fly
![Page 22: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/22.jpg)
This is where the actual fun begins!
![Page 23: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/23.jpg)
Some basic stuff: ORM
![Page 24: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/24.jpg)
![Page 25: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/25.jpg)
![Page 26: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/26.jpg)
![Page 27: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/27.jpg)
How does Rails map the attributes???
![Page 28: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/28.jpg)
![Page 29: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/29.jpg)
![Page 30: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/30.jpg)
The truth is in the source…
![Page 31: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/31.jpg)
![Page 32: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/32.jpg)
![Page 33: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/33.jpg)
![Page 34: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/34.jpg)
![Page 35: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/35.jpg)
![Page 36: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/36.jpg)
A blink into the “magic”
![Page 37: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/37.jpg)
![Page 38: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/38.jpg)
if we haven’t already generated the “dynamic” methods
![Page 39: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/39.jpg)
if we haven’t already generated the “dynamic” methods
• generate them
![Page 40: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/40.jpg)
if we haven’t already generated the “dynamic” methods
• generate them
•try to call the method with the given name again!
![Page 41: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/41.jpg)
![Page 42: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/42.jpg)
![Page 43: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/43.jpg)
for each column on the db table :
![Page 44: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/44.jpg)
for each column on the db table :
• define a “read” method
![Page 45: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/45.jpg)
for each column on the db table :
• define a “read” method (for example the Guest#name)
![Page 46: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/46.jpg)
for each column on the db table :
• define a “read” method(for example the Guest#name)
• define a “write” method
![Page 47: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/47.jpg)
for each column on the db table :
• define a “read” method(for example the Guest#name)
• define a “write” method(for example the Guest#name = …)
![Page 48: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/48.jpg)
for each column on the db table :
• define a “read” method(for example the Guest#name)
• define a “write” method(for example the Guest#name = …)
• define a “question” method
![Page 49: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/49.jpg)
for each column on the db table :
• define a “read” method(for example the Guest#name)
• define a “write” method(for example the Guest#name = …)
• define a “question” method(for example the Guest#name?)
![Page 50: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/50.jpg)
![Page 51: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/51.jpg)
PART III :
Magic happens Everywhere
![Page 52: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/52.jpg)
On the routes / Controllers
![Page 53: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/53.jpg)
![Page 54: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/54.jpg)
![Page 55: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/55.jpg)
![Page 56: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/56.jpg)
![Page 57: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/57.jpg)
![Page 58: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/58.jpg)
![Page 59: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/59.jpg)
+ 3 more by default
![Page 60: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/60.jpg)
More info on “resources” : http://api.rubyonrails.org/classes/ActionController/Resources.html
+ 3 more by default
![Page 61: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/61.jpg)
On the ORM / Models
![Page 62: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/62.jpg)
Dynamic finders
![Page 63: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/63.jpg)
Dynamic finders
![Page 64: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/64.jpg)
As said this is just a “blink”
![Page 65: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/65.jpg)
Look for more in :
• ActiveRecord associations• ActiveRecord named_scopes
• ActionController routes• ActionController rendering• ActionController format
• etc…
![Page 66: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/66.jpg)
What do we get from this?
![Page 67: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/67.jpg)
What do we get from this?
•Glue code
![Page 68: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/68.jpg)
What do we get from this?
•Glue code•Domain-aware code
![Page 69: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/69.jpg)
What do we get from this?
•Glue code•Domain-aware code
•Out of the box
![Page 70: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/70.jpg)
What do we get from this?
•Glue code•Domain-aware code
•Out of the box• Every time
![Page 71: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/71.jpg)
What do we get from this?
• Glue code• Domain-aware code
• Out of the box• Every time
• On every app
![Page 72: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/72.jpg)
Compare it with Java or .Net “enterprise”
solutions…
![Page 73: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/73.jpg)
Compare it with Java or .Net “enterprise”
solutions…
© Rubyrags.com
![Page 74: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/74.jpg)
Implement your own!!!
![Page 75: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/75.jpg)
Implement your own!!!
(Jim will give you a hint tomorrow at the Ruby
Meetup)
![Page 76: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/76.jpg)
Thanks for your time
![Page 77: A Blink Into The Rails Magic](https://reader035.vdocuments.site/reader035/viewer/2022062510/547b4ddab4af9faf158b4e08/html5/thumbnails/77.jpg)
Thanks for your time
And welcome to the magic world of
Ruby and Ruby on Rails