Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

of

MVC Demystified: Essence of Ruby on Rails Slide 1 MVC Demystified: Essence of Ruby on Rails Slide 2 MVC Demystified: Essence of Ruby on Rails Slide 3 MVC Demystified: Essence of Ruby on Rails Slide 4 MVC Demystified: Essence of Ruby on Rails Slide 5 MVC Demystified: Essence of Ruby on Rails Slide 6 MVC Demystified: Essence of Ruby on Rails Slide 7 MVC Demystified: Essence of Ruby on Rails Slide 8 MVC Demystified: Essence of Ruby on Rails Slide 9 MVC Demystified: Essence of Ruby on Rails Slide 10 MVC Demystified: Essence of Ruby on Rails Slide 11 MVC Demystified: Essence of Ruby on Rails Slide 12 MVC Demystified: Essence of Ruby on Rails Slide 13 MVC Demystified: Essence of Ruby on Rails Slide 14 MVC Demystified: Essence of Ruby on Rails Slide 15 MVC Demystified: Essence of Ruby on Rails Slide 16 MVC Demystified: Essence of Ruby on Rails Slide 17 MVC Demystified: Essence of Ruby on Rails Slide 18 MVC Demystified: Essence of Ruby on Rails Slide 19 MVC Demystified: Essence of Ruby on Rails Slide 20 MVC Demystified: Essence of Ruby on Rails Slide 21 MVC Demystified: Essence of Ruby on Rails Slide 22 MVC Demystified: Essence of Ruby on Rails Slide 23 MVC Demystified: Essence of Ruby on Rails Slide 24 MVC Demystified: Essence of Ruby on Rails Slide 25 MVC Demystified: Essence of Ruby on Rails Slide 26 MVC Demystified: Essence of Ruby on Rails Slide 27 MVC Demystified: Essence of Ruby on Rails Slide 28 MVC Demystified: Essence of Ruby on Rails Slide 29 MVC Demystified: Essence of Ruby on Rails Slide 30 MVC Demystified: Essence of Ruby on Rails Slide 31 MVC Demystified: Essence of Ruby on Rails Slide 32 MVC Demystified: Essence of Ruby on Rails Slide 33 MVC Demystified: Essence of Ruby on Rails Slide 34 MVC Demystified: Essence of Ruby on Rails Slide 35 MVC Demystified: Essence of Ruby on Rails Slide 36 MVC Demystified: Essence of Ruby on Rails Slide 37 MVC Demystified: Essence of Ruby on Rails Slide 38 MVC Demystified: Essence of Ruby on Rails Slide 39 MVC Demystified: Essence of Ruby on Rails Slide 40 MVC Demystified: Essence of Ruby on Rails Slide 41 MVC Demystified: Essence of Ruby on Rails Slide 42 MVC Demystified: Essence of Ruby on Rails Slide 43
Upcoming SlideShare
Enterprise Architectures with Ruby (and Rails)
Next
Download to read offline and view in fullscreen.

49 Likes

Share

Download to read offline

MVC Demystified: Essence of Ruby on Rails

Download to read offline

Examines the MVC design pattern and how Rails adheres to this powerful design pattern. Good introduction to Ruby on Rails framework.

Related Books

Free with a 30 day trial from Scribd

See all

MVC Demystified: Essence of Ruby on Rails

  1. MVC Demystified Webvisions 2007 Michael P. Jones [email_address] Understanding the Essence of Ruby on Rails
  2. About Session <ul><li>Web applications </li></ul><ul><li>MVC </li></ul><ul><li>Pix Patisserie </li></ul><ul><li>MVC Another Look </li></ul><ul><li>Rails Essence </li></ul><ul><li>More Rails </li></ul><ul><li>Rails Testing </li></ul><ul><li>Other MVC </li></ul>
  3. About Speaker <ul><li>Past </li></ul><ul><ul><li>Educational and Reservation software. (Java) </li></ul></ul><ul><ul><li>Founded Code in Motion. http://codeinmotion.com/ </li></ul></ul><ul><li>Present </li></ul><ul><ul><li>Creating custom Ruby on Rails applications. </li></ul></ul><ul><ul><ul><li>Recovery and prevention. </li></ul></ul></ul><ul><ul><ul><li>Screening and Interview </li></ul></ul></ul><ul><ul><ul><li>PDF generation of applications </li></ul></ul></ul><ul><ul><ul><li>Widgets </li></ul></ul></ul><ul><ul><li>Tailoring CMS Solutions </li></ul></ul><ul><ul><ul><li>Radiant, Rails based CMS with extensions for business needs of the client. </li></ul></ul></ul>
  4. Traditional Applications <ul><li>Browser directly accesses page. </li></ul><ul><ul><li>Does not centralize control </li></ul></ul><ul><ul><li>No content/style separation </li></ul></ul><ul><ul><li>Easy and fast to produce </li></ul></ul><ul><ul><li>Difficult to maintain </li></ul></ul>
  5. MVC Applications <ul><li>Browser accesses a “controller” </li></ul><ul><ul><li>Centralizes control </li></ul></ul><ul><ul><li>Clean separation of content/style </li></ul></ul><ul><ul><li>More involved to produce </li></ul></ul><ul><ul><li>Easier to maintain and expand </li></ul></ul>
  6. MVC <ul><li>MVC is an Architectural Design Pattern </li></ul><ul><li>Separates a web application into three different modules. </li></ul>
  7. Design Pattern <ul><li>A pattern that has been developed to help programmers cope with common problems. </li></ul><ul><li>Blueprints on how to construct something. </li></ul>
  8. MVC Means <ul><li>Most Vexing Conundrum (Amy Hoy) </li></ul><ul><li>Model | View | Controller </li></ul>
  9. Trip to Pix <ul><li>A Patisserie in Portland </li></ul>http://qwendy.typepad.com/
  10. Typical Bakery Interaction <ul><li>Request a tasty treat from the baker </li></ul>http://www.pixpatisserie.com/
  11. Baker Gathers Ingredients <ul><li>Baker gathers raw ingredients to fulfill the request. </li></ul><ul><li>Some requests utilize same ingredients. </li></ul>http://www.flickr.com/photos/moria/92792777/
  12. Baker Select Pan <ul><li>The pan dictates what the response looks like. </li></ul>http://www.flickr.com/photos/tracyhunter/113563802/
  13. Baker responds with your treat http://www.pixpatisserie.com/
  14. Pix Flow
  15. MVC Diagram
  16. Controller (Baker) <ul><li>Dispatches Requests and controls flow. </li></ul><ul><li>Centralizes access. </li></ul><ul><li>Interacts with Model and View. </li></ul>
  17. Model (Ingredients) <ul><li>Data representation and business logic. </li></ul><ul><li>Can be database/xml/etc </li></ul><ul><li>Business Logic </li></ul><ul><li>Examples: </li></ul><ul><ul><li>User </li></ul></ul><ul><ul><li>Bike </li></ul></ul><ul><ul><li>Question </li></ul></ul>
  18. View (Pan) <ul><li>Data presentation and user input. </li></ul><ul><li>Renders the Model in to a View. </li></ul><ul><li>Can be HTML/PDF/WML/Javascript </li></ul><ul><li>No computations, very little logic, display logic i.e. loops </li></ul>
  19. MVC Diagram
  20. MVC Advantages <ul><li>Separation of interests. </li></ul><ul><ul><li>Model centralizes business logic. </li></ul></ul><ul><ul><li>View centralizes display logic. </li></ul></ul><ul><ul><li>Controller centralizes application flow. </li></ul></ul><ul><li>Clean separation of content/style. </li></ul><ul><li>Improved decoupling. </li></ul><ul><li>Easier testing. </li></ul><ul><li>Allow multiple people to work on different parts. </li></ul>
  21. Rails and MVC <ul><li>Rails in an MVC framework </li></ul><ul><li>”… Rails is such a framework that tries to remove the complexity and drudgery of MVC, while still allowing you to realize all the benefits.” - DHH (David Heinemeier Hansson) </li></ul>
  22. Model: ActiveRecord <ul><li>ActiveRecord is a design pattern. (Martin Fowler) </li></ul><ul><li>Object wraps a row in the database. </li></ul><ul><li>Encapsulates data access. </li></ul><ul><li>Contains business logic. </li></ul><ul><li>Handles relationships. </li></ul><ul><li>Handles validation. </li></ul>
  23. ActiveRecord Code
  24. View: ActionView <ul><li>Renders the view. </li></ul><ul><li>Both .rhtml and .rxml files. </li></ul><ul><li>Provides master layouts. </li></ul><ul><li>Uses ERb (embedded ruby) for templating and control. </li></ul>
  25. ActionView Code
  26. Controller: ActionController <ul><li>Controls application flow. </li></ul><ul><li>Controls which view to use. </li></ul><ul><li>Makes data available as instance variables @var </li></ul><ul><li>Contains several actions/defs </li></ul><ul><li>Controls rendering and redirection. </li></ul>
  27. ActionController Code
  28. All Together Now http://wiki.rubyonrails.org/
  29. How it works <ul><li>your_domain.com/controller/action/id </li></ul><ul><li>Controller has actions. </li></ul><ul><li>View directory has directory for each controller. </li></ul><ul><li>Same action name as .rhtml file </li></ul><ul><li>your_domain.com/bikes/edit/2 </li></ul><ul><ul><li>Controller: bikes </li></ul></ul><ul><ul><li>Action: edit </li></ul></ul><ul><ul><li>Id: 2 </li></ul></ul>
  30. Rails Concepts <ul><li>DRY (Don’t Repeat Yourself) </li></ul><ul><li>Convention of configuration </li></ul><ul><li>Generators script/generate generator_name </li></ul><ul><li>:symbols or ‘symbols’ </li></ul><ul><ul><li>represents names and strings </li></ul></ul><ul><li>YAML machine parsable human readable. </li></ul>
  31. More ActiveRecord <ul><li>Automatically maps to a table </li></ul><ul><ul><li>No XML configs </li></ul></ul><ul><ul><li>Each row is an Object </li></ul></ul><ul><li>Several databases supported. </li></ul><ul><li>Provides </li></ul><ul><ul><li>CRUD: Create, Read, Update, Destroy </li></ul></ul><ul><ul><li>Getters/Setters </li></ul></ul><ul><ul><li>Validation: validates_presence_of, validates_format_of </li></ul></ul><ul><ul><li>Callbacks: hooks into lifecycle, trigger events before/after </li></ul></ul><ul><ul><li>Finding: Person.find(:all, :conditions => [ &quot;category IN (?)&quot;, categories], :limit => 50) </li></ul></ul>
  32. More ActiveRecord Code <ul><li>Callbacks </li></ul><ul><li>Relations </li></ul><ul><li>Validation </li></ul>
  33. More ActionView <ul><li>Layouts </li></ul><ul><ul><li>app/view/layouts/application.rhtml </li></ul></ul><ul><li>Partials </li></ul><ul><ul><li>_partial_view.rhtml </li></ul></ul><ul><ul><li>Reuse of common view elements </li></ul></ul><ul><li>Helpers </li></ul><ul><ul><li>Helper module per Controller </li></ul></ul><ul><ul><li>Contains Ruby code </li></ul></ul>
  34. More ActionView Code
  35. More ActionController <ul><li>Filters </li></ul><ul><ul><li>before , after and around processing hooks </li></ul></ul><ul><li>Routes </li></ul><ul><ul><li>Replaces apache mod_rewrite </li></ul></ul><ul><ul><li>config/routes.rb </li></ul></ul><ul><li>Caching </li></ul><ul><ul><li>Has caching to improve performance </li></ul></ul><ul><ul><ul><li>page </li></ul></ul></ul><ul><ul><ul><li>action </li></ul></ul></ul><ul><ul><ul><li>fragment </li></ul></ul></ul>
  36. More ActionController Image
  37. Pitfalls: Excess <ul><li>Model: God Object (anti-pattern) </li></ul><ul><ul><li>Too much logic in a Model, one Model too powerful. </li></ul></ul><ul><li>View: Too much logic in View </li></ul><ul><li>Controller: Anemic Domain Model (anti-pattern) </li></ul><ul><ul><li>Too much business logic in Controller. </li></ul></ul><ul><li>Cargo cult programming </li></ul><ul><ul><li>(over-)applying a design principle blindly without understanding the reasons. - (wikipedia) </li></ul></ul>
  38. Testing Rails <ul><li>Rails has great testing framework ‘baked in’ the framework </li></ul><ul><ul><li>Test stubs created when code is ‘generated’. </li></ul></ul><ul><li>Unit to test models. </li></ul><ul><ul><li>test/unit </li></ul></ul><ul><li>Functional to test views/controllers </li></ul><ul><ul><li>test/functional </li></ul></ul><ul><li>Fixtures </li></ul><ul><ul><li>Supply test data (yaml) </li></ul></ul>
  39. Unit Testing <ul><li>Separate ‘test’ database is used. </li></ul><ul><li>Fixtures supply data </li></ul><ul><li>Variety of ‘assert’ statements. </li></ul>
  40. Functional Testing <ul><li>Fixture </li></ul><ul><li>Setup </li></ul><ul><li>Tests </li></ul>
  41. Rake <ul><li>Rake is your friend. </li></ul><ul><ul><li>Database tasks </li></ul></ul><ul><ul><li>Deployment </li></ul></ul><ul><ul><li>Documentation </li></ul></ul><ul><ul><li>Testing </li></ul></ul><ul><ul><li>Cleanup </li></ul></ul>
  42. MVC Around The Web <ul><li>Java </li></ul><ul><ul><li>Struts, Spring </li></ul></ul><ul><li>.NET </li></ul><ul><ul><li>MonoRail (inspired by Rails) </li></ul></ul><ul><li>Perl </li></ul><ul><ul><li>Catalyst, MayPole </li></ul></ul><ul><li>Php </li></ul><ul><ul><li>CakePHP, Code Igniter </li></ul></ul><ul><li>Python </li></ul><ul><ul><li>Django, TurboGears </li></ul></ul><ul><li>Ruby </li></ul><ul><ul><li>Nitro, Wee </li></ul></ul>
  43. Questions? <ul><li>MVC </li></ul><ul><li>Rails </li></ul><ul><li>Pix </li></ul>
  • hteixe

    Jun. 19, 2019
  • s.perricone

    May. 20, 2016
  • kelvinlai12

    Feb. 22, 2016
  • ZerosOnes

    Dec. 25, 2015
  • AtulSinha10

    Sep. 7, 2015
  • bhargavarocky

    Aug. 17, 2015
  • thebestlightpossible

    Aug. 3, 2015
  • ErezHadad1

    Jul. 27, 2013
  • asanchez75

    Jun. 24, 2013
  • ialja

    Feb. 20, 2013
  • manojkumrm

    Oct. 21, 2011
  • dwoodwoo

    Apr. 29, 2011
  • miracsa

    Apr. 22, 2011
  • kernnerd

    Apr. 15, 2011
  • toblakai

    Sep. 10, 2010
  • hiep123

    Aug. 18, 2010
  • nikhiljosh

    May. 5, 2010
  • lanvige

    Apr. 2, 2010
  • simonmd

    Dec. 6, 2009
  • DaveLG526

    Sep. 25, 2009

Examines the MVC design pattern and how Rails adheres to this powerful design pattern. Good introduction to Ruby on Rails framework.

Views

Total views

46,538

On Slideshare

0

From embeds

0

Number of embeds

1,226

Actions

Downloads

1,430

Shares

0

Comments

0

Likes

49

×