Introduction to Ruby on Rails
Upcoming SlideShare
Loading in...5

Introduction to Ruby on Rails



Introduction to Ruby on Rails (English + Indonesian)

Introduction to Ruby on Rails (English + Indonesian)



Total Views
Views on SlideShare
Embed Views



1 Embed 12 12



Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


13 of 3 Post a comment

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

    Introduction to Ruby on Rails Introduction to Ruby on Rails Presentation Transcript

    • by niwat0ri ( )
    • WHO AM I ? research & development director at pt jerbee indonesia a newbie ruby programmer a foss & gnu/linux enthusiast a blogger a comic artist ( member of id-ruby community
    • WHY RUBY ON RAILS? kenapa ruby on rails?
    • buzzword, trend, hype kok bisa? ada apa? cuma euforia? apa memang bagus? ruby on rails that... ruby on rails this... ruby on rails that... ruby on rails that... ruby on rails this... ruby on rails that...
    • code your idea ASAP! technopreuneur, ubah ide anda menjadi web secepatnya !
    • powered by ruby on rails top web berbasis rails berdasarkan alexa rating oktober 2008
    • powered by ruby on rails non-publik? proyek? jobs? backend? intranet? outsorcing?
    • web dev. competition peluang, mengejar ketinggalan, persaingan, learning curve
    • programmer happiness ruby, convention over configuration, don't repeat yourself, fun
    • one man army start up kecil & solo freelancer harus agile !
    • good & clean code productivity, ruby's OOP, built in AJAX, RESTful, MVC, testing
    • WHAT IS RUBY ON RAILS? ok, kalau begitu apa sih ruby on rails itu?
    • WEB APP. = NOODLE OLD MANUAL PROCESS framework means... FASTER
    • WEB APP. FRAMEWORK MENU JAVA PYTHON PHP RUBY apa selera anda? Struts etc. Django etc. CodeIgniter etc. Ruby on Rails
    • MVC model - view - controller
    • the rails way ! convention over configuration (COC) ada struktur, penamaan dan aturan-aturan yang berlaku don't repeat yourself (DRY) menghemat waktu, mudah di-manage, reusable code
    • script/console macho & detail bersama command line
    • rails example script/generate model User name:string address:string birthday:date rake db:migrate script/console Loading development environment (Rails 2.1.0) >> User => User(id: integer, name: string, address:string, birthday:date)
    • $> errr... ? allergic to console? IDE also available
    • script/generate hasilkan code sakti secara instant
    • script/generate model Friendship user_id:integer friend_id:integer relation:string script/destroy model User script/generate scaffold User name:string address:string birthday:date
    • Create Read Update Delete
    • script/server aneka server & skenario deployment
    • script/server script/server -e production -p 4000 Server: Apache, WEBrick, Mongrel, nginx, Lighttpd Environment: development, production, test
    • script/plugins aneka rupa reusable code tersedia
    • script/plugins install restful_authentication script/plugin install git:// thoughtbot/paperclip.git gem install aka_time
    • layout rendering, images, css, javascript
    • MVC MODEL - view - controller
    • ActiveRecord Object Relation Mapping (ORM) Rails MVC's model foundation Database Agnostic Tables map to classes Rows map to objects Columns map to object attributes Convention: table = plural model = singular with capital
    • User.find(1) # SELECT * FROM users WHERE id=1 User.find_by_name 'Icha Aprillia' # SELECT * FROM users WHERE name='Icha Aprillia' User.find_by_login_and_email 'icha', '' # SELECT * FROM users WHERE login='icha' AND emai='' User.find :all, :order => 'login DESC' # SELECT * FROM users ORDER BY login DESC User.find :all, :conditions => [quot;login=?quot;,quot;ichaquot;] # SELECT * FROM users WHERE login='icha'
    • Model's Associations Friend = User User id name address birthday id name address birthday Friendship id user_id friend_id relation
    • MODEL'S ASSOCIATIONS class User < ActiveRecord::Base has_many :friendships has_many :friends, :through => :friendships end class Friendship < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => quot;Userquot;, :foreign_key => quot;friend_idquot; end User_1 had a friendship with his friend, the User_2. User_1 could have many friendship with his friends.
    • User.find(1).friends # SELECT * FROM users INNER JOIN friendships ON = friendships.friend_id WHERE ((friendships.user_id = 1) # Listing User_1's friends User.find(1).friends.count # The numbers of User_1's friends
    • MVC model - view - CONTROLLER
    • ActionController Separation of business logic & presentation No logic in view! (Not so) Convention: Controller name = plural
    • CONTROLLERS class UsersController < ApplicationController def show @user = User.find(params[:id]) @friends = User.find(params[:id]).friends end ... Action “show” will be collecting user information and all of user's friends information.
    • MVC model - VIEW - controller
    • VIEW <div id=quot;profilequot;> <h2><%= %>'s Profile</h2> <p> <%=h %> <b>Name:</b> <%=h %> </p> <p> <b>Address:</b> <%=h @user.address %> <%= link_to, </p> <p> :controller => quot;usersquot;, :action => quot;showquot;, <b>Birthday:</b> <%=h @user.birthday %> </p> <%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %> </div> :id => %> <div id=quot;friendquot;> <h2><%= %>'s Friends</h2> <ul> <% for friend in @friends %> <li><%= link_to, :controller => quot;usersquot;, :action => quot;showquot;, :id => %></li> <% end %> </ul> </div> # app/views/user/show.html.erb.
    • HOW TO START? mulai dari mana ya?
    • DEMO & DISCUSSION sesi demonstrasi & diskusi
    • Thank You ! Diki Andeas aka. niwat0ri Email: , Website: Free images taken from Flickr collection of