• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Server-side Web development via Ruby on Rails
 

Server-side Web development via Ruby on Rails

on

  • 3,904 views

 

Statistics

Views

Total Views
3,904
Views on SlideShare
3,904
Embed Views
0

Actions

Likes
2
Downloads
0
Comments
0

0 Embeds 0

No embeds

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

    Server-side Web development via Ruby on Rails Server-side Web development via Ruby on Rails Presentation Transcript

    • Ruby on Rails
      Server-side web development
      VladStoian
      Victor Porof
    • What we’ll talk about
      What is Ruby on Rails?
      A brief history
      MVC architecture in a nutshell
      Distinctive framework features
      Why Ruby? Why Rails?
      Demo
    • What is RoR?
      Open Source
      Abstraction providing generic server-side functionality
      Used for web application development
      It’s a framework for the Ruby language
      ..so don’t confuse it with plain Ruby!
    • A brief history
      Originates in David Heinemeier Hansson’s work
      First released in July 2004
      Apple ships RoR with Mac OS X Leopard since 2007
      Major new developments with v2.3 in 2009
      Templates
      Generate skeleton applications
      Custom gems and configurations
      Latest: v3.0.5, 27 February 2011
    • MVC architecture
      RoR is based on the Model-View-Controller design
      It’s an architectural development pattern
      Widely used in many other frameworks:
      Oracle Application Framework, Cocoon, JSF (Java)
      ASP.NET (C#)
      SproutCore, JavascriptMVC (Javascript)
      Django, Pylons (Python)
      CakePHP(PHP)
      PureMVC (many languages)
    • MVC on Rails
      Models are Ruby classes, used to store and validate data
      Handles migrations
      They talk to databases
      MySQL
      SQLite
      PostgreSQL
      NoSQL
      MongoDB
      Cassandra
      “Chubby guy in the back room” crunching the numbers
    • Model snippet
      class Person < ActiveRecord::Base
      validates_presence_of :name
      has_many :wifes
      end
      Person.create(:name => ”Muhammad Ali”).valid? # => true
      Person.create(:name => nil).valid? # => false
    • Migration snippet
      class AddReceiveNewsletterToUsers < ActiveRecord::Migration
      defself.up
      change_table :users do |t|
      t.boolean :receive_newsletter, :default => false
      end
      User.update_all ["receive_newsletter = ?", true]
      end
      defself.down
      remove_column :users, :receive_newsletter
      end
      end
    • MVC on Rails
      What the user sees
      HTML, CSS, XML, Javascript (jQuery)
      JSON, RSS, Atom
      Automatically generated “view-puppets”
      Visual representation of data
      Does not have direct access to the model!
      It shouldn’t do lots of processing or calculation
    • View snippet
      <!-- app/views/items/new.rhtml -->
      <%= form_tag :action => “create” %>
      Name: <%= text_field“item”, “name”%><br/>
      Email: <%= text_field“item”, ”email”%><br/>
      Password: <%= hidden_field “item”, “password”%><br/>
      <%= submit_tag %>
      <%= end_form_tag %>
    • MVC on Rails
      Gateway between the model and the view
      Handles user requests
      Does parsing and data submissions
      Takes care of sessions, cookies
      Works out what data to show and what views to render
      ”The best controller: it gives orders without knowing (or caring) how it gets done”
    • Controller snippet
      classItemsController < ApplicationController
      def edit
      @item = Item.find(params[:id])
      ifrequest.post?
      @item.update_attributes(params[:item])
      redirect_to :action => 'edit', :id => @item.id
      end
      end
      end
    • MVC on Rails
      To summarize:
      Keep your view code skinny
      Keep your controller code skinny
      The fatness is in the model
    • Distinctive framework features
      Code generators
      Awesome built-in functions => rapid development
      Tons of “gems” to choose from
      Cross-platform compatibility
      Automated operation (CRUD)
      Create, Retrieve, Automate and Delete
      Simplified testing (Rake script)
    • Code generator snippet
      #model generator (general)
      ruby script/generate model model_name #(in v2.3)
      rails generate model model_name #(in v3)
      #model generator (example)
      rails generate model user name:stringhashed_password:string
      #controller generator (general)
      ruby script/generate controller controller_namemethod_name(s) (in v2.3)
      rails generate controller controller_namemethod_name(s) (in v3)
      #controller generator (example)
      rails generate controller store index
    • RoR servers
      Mongrel
      Webbrick
      Thin
      Apache (mod_passanger)
      ..so it’s very scalable!
    • Famous projects on Rails
      Twitter (microblogging)
      Crunchbase (companies database)
      BaseCamp (project management)
      Hulu (online tv)
      Yellowpages.com (phone database)
      Xing (business network)
    • Why Ruby?
      Interpreted language => greater flexibility
      Provides JIT (just in time compilation)
      Garbage collection
      Able to generate code on the fly
      Cleaner syntax (no more “Verbose verbose is too verbose for verbose”)
      Many implementations:
      Jruby, IronRuby, Rubinius(Ruby + C++), MacRuby (ObjC)
    • Why Rails?
      Based on Ruby
      Easy to implement CGI scripts
      Rapid web-application development
      Designed to make programming work easier
      Less coding, more functionality
      Thousands of plugins
      Don’t reinvent the wheel
    • Creating a blog with