Ruby on Rails 3<br />December 2010, BarCamp Saigon<br />Nam Ho<br />
About me<br />Working at KMS Technology<br />A member of ALT.NET Saigon group<br />2<br />@hotrannam<br />
Ruby on Rails<br />Web framework<br />Ruby<br />Model-View-Controller pattern<br />Open source<br />Created by David H. Ha...
Ruby on Rails<br />Full-stack framework<br />Gives everything you need to create a web app<br />Pretty much forces to use ...
Confidential<br />5<br />Getting started<br />
Starting a new app<br />rails  new  barcamp<br />6<br />
Starting a new app<br />rails  server<br />7<br />
Starting a new app<br />8<br />
9<br />Quick and easy?<br />More information: http://rubyonrails.org/download<br />
Confidential<br />10<br />Model<br />
Model<br />Contains almost the application logic<br />The heart of application<br />Object Relational Mappings<br />Active...
Active Record<br />rails  g  model  Article<br />rake  db:migrate<br />rails  console<br />The  generated  model  class<br...
Active Record: CRUD<br />article = Article.new<br />article.title = “Rails 3”<br />article.body = “Barcamp Saigon”<br />ar...
Active Record: CRUD<br />article = Article.first<br />article = Article.find(id)<br />article = Article.find_by_title(“Rai...
Active Record: CRUD<br />article.title = “Web development with Rails 3”<br />article.save<br />Update<br />
Active Record: CRUD<br />article.destroy<br />Article.delete(id)<br />Article.delete_all(“created_at < '2011-01-01'")<br /...
Active Record: Scope<br />A scope represents a narrowing of a database query<br />articles = Article.published.where_title...
Active Record: Validation<br />article.title = nil<br />article.save<br />article.errors.full_messages<br />Confidential<b...
Active Record: Custom Val.<br />comment = article.comments.create :body => “Great article!”<br />comment.errors.full_messa...
Active Record: Relationship<br />Confidential<br />20<br />1 : 1<br />
Active Record: Relationship<br />Confidential<br />21<br />1 : n<br />
Active Record: Relationship<br />Confidential<br />22<br />n : n<br />
Active Record: Callbacks<br />before_create<br />after_create<br />before_save<br />after_save<br />before_destroy<br />af...
Active Record: Observers<br />When the Model is in a clutter by callbacks<br />Hard to read the Model<br />Observers are c...
Active Record: Db Migration<br />rails   g   migration  review<br />rake   db:migrate<br />
Confidential<br />26<br />Controller<br />
Controller<br />Handle requests and issue responses<br />Pull data from the Model<br />Choose the View to render<br />An a...
Controller: Rendering responses<br />A response is rendered with the render command<br />Redirects are made with the redir...
Controller: Filters<br />before_filter<br />after_filter<br />around_filter<br />Separation of cross-cutting concerns<br />
Controller: Example<br />rails   g   controller   article<br />
Routing<br />Forward requests to action methods<br />
Restful routes and resources<br />
View<br />
View<br />.html.erb: used for rendering HTML<br />.js.erb: used for AJAX functionality<br />.xml.builder: used for RSS/Ato...
View<br />Helper methods to generate links, forms, and JavaScript, and to format text<br />Partials are templates that ren...
Action Mailer<br />Bundler: manages dependencies<br />etc.<br />Confidential<br />36<br />Others<br />
Confidential<br />37<br />Discussion!<br />http://github.com/hotrannam/barcamp<br />
Upcoming SlideShare
Loading in...5
×

Ruby on Rails 3

1,171

Published on

My presentation at Barcamp Saigon 2010

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,171
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Ruby on Rails 3"

  1. 1. Ruby on Rails 3<br />December 2010, BarCamp Saigon<br />Nam Ho<br />
  2. 2. About me<br />Working at KMS Technology<br />A member of ALT.NET Saigon group<br />2<br />@hotrannam<br />
  3. 3. Ruby on Rails<br />Web framework<br />Ruby<br />Model-View-Controller pattern<br />Open source<br />Created by David H. Hansson<br />Maintained and developed by Rails core team<br />3<br />
  4. 4. Ruby on Rails<br />Full-stack framework<br />Gives everything you need to create a web app<br />Pretty much forces to use it<br />Convention over configuration<br />Common structures and naming conventions<br />Don’t break conventions unless you really have to<br />Don’t repeat yourself<br />Code is written in just one place<br />Easier for changes<br />Testing<br />4<br />
  5. 5. Confidential<br />5<br />Getting started<br />
  6. 6. Starting a new app<br />rails new barcamp<br />6<br />
  7. 7. Starting a new app<br />rails server<br />7<br />
  8. 8. Starting a new app<br />8<br />
  9. 9. 9<br />Quick and easy?<br />More information: http://rubyonrails.org/download<br />
  10. 10. Confidential<br />10<br />Model<br />
  11. 11. Model<br />Contains almost the application logic<br />The heart of application<br />Object Relational Mappings<br />Active Record<br />Data Mapper<br />Mongo Mapper<br />11<br />
  12. 12. Active Record<br />rails g model Article<br />rake db:migrate<br />rails console<br />The generated model class<br />Table and Class name convention<br />The generated database migration file <br />
  13. 13. Active Record: CRUD<br />article = Article.new<br />article.title = “Rails 3”<br />article.body = “Barcamp Saigon”<br />article.save<br />Create<br />
  14. 14. Active Record: CRUD<br />article = Article.first<br />article = Article.find(id)<br />article = Article.find_by_title(“Rails 3”)<br />articles = Artcile.all()<br />Lots of dynamic finders<br />Read<br />
  15. 15. Active Record: CRUD<br />article.title = “Web development with Rails 3”<br />article.save<br />Update<br />
  16. 16. Active Record: CRUD<br />article.destroy<br />Article.delete(id)<br />Article.delete_all(“created_at < '2011-01-01'")<br />Delete<br />
  17. 17. Active Record: Scope<br />A scope represents a narrowing of a database query<br />articles = Article.published.where_title(“Rails”)<br />Confidential<br />17<br />
  18. 18. Active Record: Validation<br />article.title = nil<br />article.save<br />article.errors.full_messages<br />Confidential<br />18<br />
  19. 19. Active Record: Custom Val.<br />comment = article.comments.create :body => “Great article!”<br />comment.errors.full_messages<br />Confidential<br />19<br />
  20. 20. Active Record: Relationship<br />Confidential<br />20<br />1 : 1<br />
  21. 21. Active Record: Relationship<br />Confidential<br />21<br />1 : n<br />
  22. 22. Active Record: Relationship<br />Confidential<br />22<br />n : n<br />
  23. 23. Active Record: Callbacks<br />before_create<br />after_create<br />before_save<br />after_save<br />before_destroy<br />after_destroy<br />
  24. 24. Active Record: Observers<br />When the Model is in a clutter by callbacks<br />Hard to read the Model<br />Observers are callbacks but in a separate class<br />Good at readability<br />Separation of concerns<br />
  25. 25. Active Record: Db Migration<br />rails g migration review<br />rake db:migrate<br />
  26. 26. Confidential<br />26<br />Controller<br />
  27. 27. Controller<br />Handle requests and issue responses<br />Pull data from the Model<br />Choose the View to render<br />An action is a public method and/or a corresponding method<br />
  28. 28. Controller: Rendering responses<br />A response is rendered with the render command<br />Redirects are made with the redirect_to command<br />An action can only render a response once<br />
  29. 29. Controller: Filters<br />before_filter<br />after_filter<br />around_filter<br />Separation of cross-cutting concerns<br />
  30. 30. Controller: Example<br />rails g controller article<br />
  31. 31. Routing<br />Forward requests to action methods<br />
  32. 32. Restful routes and resources<br />
  33. 33. View<br />
  34. 34. View<br />.html.erb: used for rendering HTML<br />.js.erb: used for AJAX functionality<br />.xml.builder: used for RSS/Atom<br />
  35. 35. View<br />Helper methods to generate links, forms, and JavaScript, and to format text<br />Partials are templates that render a part of a page<br />Layouts a templates that contains common page elements<br />
  36. 36. Action Mailer<br />Bundler: manages dependencies<br />etc.<br />Confidential<br />36<br />Others<br />
  37. 37. Confidential<br />37<br />Discussion!<br />http://github.com/hotrannam/barcamp<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×