Your SlideShare is downloading. ×
0
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Ruby on Rails 3
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ruby on Rails 3

1,153

Published on

My presentation at Barcamp Saigon 2010

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,153
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby on Rails 3<br />December 2010, BarCamp Saigon<br />Nam Ho<br />
  • 2. About me<br />Working at KMS Technology<br />A member of ALT.NET Saigon group<br />2<br />@hotrannam<br />
  • 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. 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. Confidential<br />5<br />Getting started<br />
  • 6. Starting a new app<br />rails new barcamp<br />6<br />
  • 7. Starting a new app<br />rails server<br />7<br />
  • 8. Starting a new app<br />8<br />
  • 9. 9<br />Quick and easy?<br />More information: http://rubyonrails.org/download<br />
  • 10. Confidential<br />10<br />Model<br />
  • 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. 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. Active Record: CRUD<br />article = Article.new<br />article.title = “Rails 3”<br />article.body = “Barcamp Saigon”<br />article.save<br />Create<br />
  • 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. Active Record: CRUD<br />article.title = “Web development with Rails 3”<br />article.save<br />Update<br />
  • 16. Active Record: CRUD<br />article.destroy<br />Article.delete(id)<br />Article.delete_all(“created_at < '2011-01-01'")<br />Delete<br />
  • 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. Active Record: Validation<br />article.title = nil<br />article.save<br />article.errors.full_messages<br />Confidential<br />18<br />
  • 19. Active Record: Custom Val.<br />comment = article.comments.create :body => “Great article!”<br />comment.errors.full_messages<br />Confidential<br />19<br />
  • 20. Active Record: Relationship<br />Confidential<br />20<br />1 : 1<br />
  • 21. Active Record: Relationship<br />Confidential<br />21<br />1 : n<br />
  • 22. Active Record: Relationship<br />Confidential<br />22<br />n : n<br />
  • 23. Active Record: Callbacks<br />before_create<br />after_create<br />before_save<br />after_save<br />before_destroy<br />after_destroy<br />
  • 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. Active Record: Db Migration<br />rails g migration review<br />rake db:migrate<br />
  • 26. Confidential<br />26<br />Controller<br />
  • 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. 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. Controller: Filters<br />before_filter<br />after_filter<br />around_filter<br />Separation of cross-cutting concerns<br />
  • 30. Controller: Example<br />rails g controller article<br />
  • 31. Routing<br />Forward requests to action methods<br />
  • 32. Restful routes and resources<br />
  • 33. View<br />
  • 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. 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. Action Mailer<br />Bundler: manages dependencies<br />etc.<br />Confidential<br />36<br />Others<br />
  • 37. Confidential<br />37<br />Discussion!<br />http://github.com/hotrannam/barcamp<br />

×