Ruby on Rails 3
Upcoming SlideShare
Loading in...5
×
 

Ruby on Rails 3

on

  • 1,354 views

My presentation at Barcamp Saigon 2010

My presentation at Barcamp Saigon 2010

Statistics

Views

Total Views
1,354
Views on SlideShare
1,097
Embed Views
257

Actions

Likes
0
Downloads
11
Comments
0

3 Embeds 257

http://hotrannam.wordpress.com 187
http://altnetsaigon.wordpress.com 68
url_unknown 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ruby on Rails 3 Ruby on Rails 3 Presentation Transcript

  • Ruby on Rails 3
    December 2010, BarCamp Saigon
    Nam Ho
  • About me
    Working at KMS Technology
    A member of ALT.NET Saigon group
    2
    @hotrannam
  • 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
  • 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
  • Confidential
    5
    Getting started
  • Starting a new app
    rails new barcamp
    6
  • Starting a new app
    rails server
    7
  • Starting a new app
    8
  • 9
    Quick and easy?
    More information: http://rubyonrails.org/download
  • Confidential
    10
    Model
  • Model
    Contains almost the application logic
    The heart of application
    Object Relational Mappings
    Active Record
    Data Mapper
    Mongo Mapper
    11
  • 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
  • Active Record: CRUD
    article = Article.new
    article.title = “Rails 3”
    article.body = “Barcamp Saigon”
    article.save
    Create
  • Active Record: CRUD
    article = Article.first
    article = Article.find(id)
    article = Article.find_by_title(“Rails 3”)
    articles = Artcile.all()
    Lots of dynamic finders
    Read
  • Active Record: CRUD
    article.title = “Web development with Rails 3”
    article.save
    Update
  • Active Record: CRUD
    article.destroy
    Article.delete(id)
    Article.delete_all(“created_at < '2011-01-01'")
    Delete
  • Active Record: Scope
    A scope represents a narrowing of a database query
    articles = Article.published.where_title(“Rails”)
    Confidential
    17
  • Active Record: Validation
    article.title = nil
    article.save
    article.errors.full_messages
    Confidential
    18
  • Active Record: Custom Val.
    comment = article.comments.create :body => “Great article!”
    comment.errors.full_messages
    Confidential
    19
  • Active Record: Relationship
    Confidential
    20
    1 : 1
  • Active Record: Relationship
    Confidential
    21
    1 : n
  • Active Record: Relationship
    Confidential
    22
    n : n
  • Active Record: Callbacks
    before_create
    after_create
    before_save
    after_save
    before_destroy
    after_destroy
  • 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
  • Active Record: Db Migration
    rails g migration review
    rake db:migrate
  • Confidential
    26
    Controller
  • 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
  • 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
  • Controller: Filters
    before_filter
    after_filter
    around_filter
    Separation of cross-cutting concerns
  • Controller: Example
    rails g controller article
  • Routing
    Forward requests to action methods
  • Restful routes and resources
  • View
  • View
    .html.erb: used for rendering HTML
    .js.erb: used for AJAX functionality
    .xml.builder: used for RSS/Atom
  • 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
  • Action Mailer
    Bundler: manages dependencies
    etc.
    Confidential
    36
    Others
  • Confidential
    37
    Discussion!
    http://github.com/hotrannam/barcamp