ruby on rails. best practices
DESCRIPTION
Ruby on Rails. Best PracticesIL Ruby UndergroundVladimir Tkach teamco at gmail.comhttp://teamco-anthill.blogspot.comTRANSCRIPT
![Page 1: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/1.jpg)
Ruby on Rails Best Practices
http://rubyonrails.org
Wondering why Ruby is so popular? Its fans call it a beautiful, artful language. And yet, they say it’s handy and practical.
http://www.ruby-lang.org/
Vladimir Tkach
![Page 2: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/2.jpg)
How to?
© SAP 2007 / Page 2
![Page 3: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/3.jpg)
Rails Best Practices
© SAP 2007 / Page 3
![Page 4: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/4.jpg)
Concept: What’s good code?
© SAP 2007 / Page 4
![Page 5: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/5.jpg)
Move finder to named_scope / scope
© SAP 2007 / Page 5
![Page 6: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/6.jpg)
Use model association
© SAP 2007 / Page 6
![Page 7: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/7.jpg)
Use scope access
© SAP 2007 / Page 7
![Page 8: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/8.jpg)
Add model virtual attribute
© SAP 2007 / Page 8
![Page 9: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/9.jpg)
Use model callback
© SAP 2007 / Page 9
![Page 10: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/10.jpg)
Use Model Callback
© SAP 2007 / Page 10
%>
![Page 11: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/11.jpg)
Replace Complex Creation with Factory Method
© SAP 2007 / Page 11
![Page 12: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/12.jpg)
Replace Complex Creation with Factory Method
© SAP 2007 / Page 12
![Page 13: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/13.jpg)
Move Model Logic into the Model
© SAP 2007 / Page 13
![Page 14: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/14.jpg)
model.collection_model_ids (many-to-many)
© SAP 2007 / Page 14
![Page 15: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/15.jpg)
model.collection_model_ids (many-to-many)
© SAP 2007 / Page 15
![Page 16: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/16.jpg)
model.collection_model_ids (many-to-many)
© SAP 2007 / Page 16
![Page 17: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/17.jpg)
Nested Model Forms (one-to-one)
© SAP 2007 / Page 17
![Page 18: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/18.jpg)
Nested Model Forms (one-to-one)
© SAP 2007 / Page 18
![Page 19: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/19.jpg)
Nested Model Forms (one-to-many)
© SAP 2007 / Page 19
![Page 20: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/20.jpg)
Keep Finders on Their Own Model
© SAP 2007 / Page 20
![Page 21: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/21.jpg)
Keep Finders on Their Own Model
© SAP 2007 / Page 21
![Page 22: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/22.jpg)
Love named_scope
© SAP 2007 / Page 22
![Page 23: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/23.jpg)
Love named_scope
© SAP 2007 / Page 23
![Page 24: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/24.jpg)
the Law of Demeter
© SAP 2007 / Page 24
![Page 25: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/25.jpg)
DRY: Metaprogramming
© SAP 2007 / Page 25
![Page 26: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/26.jpg)
DRY: Metaprogramming
© SAP 2007 / Page 26
![Page 27: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/27.jpg)
Extract into Module
© SAP 2007 / Page 27
![Page 28: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/28.jpg)
Extract to composed class
© SAP 2007 / Page 28
![Page 29: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/29.jpg)
Extract to composed class
© SAP 2007 / Page 29
![Page 30: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/30.jpg)
Use Observer
© SAP 2007 / Page 30
![Page 31: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/31.jpg)
Use Observer
© SAP 2007 / Page 31
![Page 32: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/32.jpg)
Move code into controller
© SAP 2007 / Page 32
![Page 33: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/33.jpg)
Move code into model
© SAP 2007 / Page 33
![Page 34: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/34.jpg)
Move code into helper
© SAP 2007 / Page 34
![Page 35: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/35.jpg)
Replace instance variable with local variable
© SAP 2007 / Page 35
![Page 36: Ruby on rails. Best practices](https://reader034.vdocument.in/reader034/viewer/2022042816/558c18f3d8b42ad3718b46aa/html5/thumbnails/36.jpg)
© SAP 2007 / Page 36
§ http://www.ruby-lang.org/en/ § http://www.ruby-lang.org/en/documentation/ § http://rubyonrails.org/ § http://guides.rubyonrails.org/v2.3.8/index.html
§ http://teamco-anthill.blogspot.com
Thank you!