This document summarizes a presentation about Ruby on Rails given at BarCamp Saigon in December 2010. It introduces Ruby on Rails as a full-stack web framework built on Ruby that follows conventions over configurations and Don't Repeat Yourself (DRY) principles. It discusses starting a new Rails application, using the model, view, controller (MVC) pattern with Active Record to manage data and perform CRUD operations. It also covers routing, controllers, views, mailers and other Rails features.
2. About me Working at KMS Technology A member of ALT.NET Saigon group 2 @hotrannam
3. Ruby on Rails Web framework Ruby Model-View-Controller pattern Open source Created by David H. Hansson Maintained and developed by Rails core team 3
4. Ruby on Rails Full-stack framework Gives everything you need to create a web app Pretty much forces to use it Convention over configuration Common structures and naming conventions Don’t break conventions unless you really have to Don’t repeat yourself Code is written in just one place Easier for changes Testing 4
11. Model Contains almost the application logic The heart of application Object Relational Mappings Active Record Data Mapper Mongo Mapper 11
12. Active Record rails g model Article rake db:migrate rails console The generated model class Table and Class name convention The generated database migration file
23. Active Record: Callbacks before_create after_create before_save after_save before_destroy after_destroy
24. Active Record: Observers When the Model is in a clutter by callbacks Hard to read the Model Observers are callbacks but in a separate class Good at readability Separation of concerns
25. Active Record: Db Migration rails g migration review rake db:migrate
27. Controller Handle requests and issue responses Pull data from the Model Choose the View to render An action is a public method and/or a corresponding method
28. Controller: Rendering responses A response is rendered with the render command Redirects are made with the redirect_to command An action can only render a response once
34. View .html.erb: used for rendering HTML .js.erb: used for AJAX functionality .xml.builder: used for RSS/Atom
35. View Helper methods to generate links, forms, and JavaScript, and to format text Partials are templates that render a part of a page Layouts a templates that contains common page elements