Rapid Development
    with Rails
About me
•          / xdite

• using Rails since 2007
• http://blog.xdite.net
• xdite@techbang.com.tw
Lead Developer & Manager
• Rails
• Rapid Development with Rails
Ruby on Rails
• Since 2004, DHH from 37 signals
•
  • DRY / Agile / Rapid / Cooooool !!
•
  • Developer /                /        /
           ....
• Developer
•
•
•
...
...
Developer
•           PHP Developer

•             PHP Developer

•       Convention

•     Developer

•           Rails Developer
•
•
•
•   Developer
•
• Rails 3 > Django > Rails 2 > Zend >
    Symfony >>>>>> CakePHP
•
•                            1M PV /day

•
•
    •   code

    •   Test

    •   Version Control   )

•
Rapid Development?
•5      CRUD

• XXX
•
•
•
•
•
•
..?
DELIVER
Rapid ?
FAIL!
•
•
•
•
development model
Rails
Rails
•
•
Rails
•
•
Rails
•
•
•
•           =>   =>
•
•
•
•       do better

•   /   solution
Rapid Development ?
Team Development
•
•
•
•
Team Development
•
•            +          = Team

• Opensource plugin +   = Team
Convention / Practices
Rails
• Community-based best practices
• Continuous revolution
• contributed by top developers
• cutting-edge technologies & ideas running
  on production
• Online training courses provided by Google
Rails
        ....
{   }
Rails
• Community-based best practices
• Continuous revolution
• contributed by top developers
• cutting-edge technologies & ideas running
  on production
!
Rails
Scaling Rails by Default
                                     http://slidesha.re/dkJjOB




• Client-side Performance Tuning
• Client-side Performance Tuning
 • CDN
image_tag
http://asset.example.org/photos/small.jpg?1269316198
• Client-side Performance Tuning
 • CDN
 • Minimal HTTP Request
<%= javascript_include_tag :default, :cache => true %>
<%=stylesheet_link_tag “main”, :cache => true %>



http://asset.example.org/javascripts/all.js?1269316198
http://asset.example.org/stylesheets/all.css?1269316198
• Client-side Performance Tuning
 • CDN
 • Minimal HTTP Request
 • Parallel Download
config.action_controller.asset_host                  =
                 “asset%d.example.org”

http://asset1.example.org/javascripts/all.js?1269316198
http://asset2.example.org/javascripts/all.js?1269316198
http://asset3.example.org/javascripts/all.js?1269316198
http://asset4.example.org/javascripts/all.js?1269316198
• Client-side Performance Tuning
 • CDN
 • Minimal HTTP Request
 • Parallel Download
 • Cache Control
def index
  do_somthing
  expires_in 10.minutes
end




header[“Cache-Control”] = “max-age=600”
Scaling Rails by Default
                                     http://slidesha.re/dkJjOB




• Client-side Performance Tunning
 • CDN
 • Minimal HTTP Request
 • Parallel Download
 • Cache Control
 • ETags, Last Modified.....etc
• Common sense of DB tuning
• Common sense of DB tuning
 • Avoid N+1 Query
             using “bullet” plugin , :include => [:comment]
• Common sense of DB tuning
 • Avoid N+1 Query
 • Use Counter Cache
              belongs_to :post, :counter_cache => “true”
• Common sense of DB tuning
 • Avoid N+1 Query
 • Use Counter Cache
 • Use CONSTANT
              CONSTANT will cache in memory
• Common sense of DB tuning
 • Avoid N+1 Query
 • Use Counter Cache
 • Use CONSTANT
 • ADD INDEX
                EXPLAIN every query, avoid table scan
                using “rails_index” plugin
• Common sense of DB tuning
 • Avoid N+1 Query
 • Use Counter Cache
 • Use CONSTANT
 • ADD INDEX
 • SELECT ONLY NEED
                  using “scrooge” plugin replace SELECT *
• Version Control Everything
• Version Control Everything
 • Git cheap branches bring cheap feature
• Version Control Everything
 • Git
 • db migration
        version control db schema
• Version Control Everything
 • Git
 • db migration
 • package management config
       version control package dependency
Gemfile
Available since 2.3.x +
• Version Control Everything
 • Git
 • db migration
 • package management config
 • deployment
        using Capistrano to rollback back each build easily
• Automate Everything
• Automate Everything
 • template
     authentication, permission control, facebook integration, pagination,admin panel,
     seach engine,job worker,mailer....etc.

     rails blog -m ~/template.rb

     rails blog -m http://gist.github.com/31208.txt

     rake rails:template LOCATION=~/template.rb
• Automate Everything
 • template
 • deployment
        * memcached, search engine, mailer, job worker, db migrate....etc.
        * 1 machine, 2+ machines, 10+ machines ....
        * Capistrano auto deployment + Deploy VMs....
• Code Readability
 • OOP / Design Pattern
 • MVC
 • Rails Best Practice               http://bit.ly/fIX3NV


 • Writing Efficiently Ruby Code      http://bit.ly/e0PpPF


 • Writing team own best practices   http://bit.ly/fL6aGI
• Product Quality
 • refactor architecture
 • SEO tuning
 • UI tuning
 • Pageview tuning
 • Business tuning
• Modern Architecture
 • Arel
 • Rack
 • ActiveModel
 • Bundler
• Modern Architecture
 • Arel
   Relational Algebra for Ruby

   simplifies the generation complex of SQL queries

   adapts to various RDBMS systems
Rack   Rack middleware
                                    http://bit.ly/aZiOIs




• Modern Architecture
 • Rack
• Modern Architecture
 • ActiveModel
   Everybody loves ActiveRecord’s feature

                      ActionPack helpers

                      Module

           Naming, Conversion, AttributeMethods, Callback, Dirty,
           MassAssignment Security,Observing,Serialization,Translation
• Modern Architecture
 • Bundler
   1 project have 10-20+ gem / plugins

    A require ‘Z’ v=0.2.1   B require ‘Z’ v=0.1.2 => conflict!

    some plugin only have trunk version, especially when we are in Rails 3.0.0 pre
Gemfile
Available since 2.3.x +
• Modern Architecture
 • Bundler
   Dependency Resolution
   Groups of Dependencies
    support git , branch , tag

    bundle lock
survey
• Compass       Ruby   CSS , CSS module   http://bit.ly/i2XLyZ


• CoffeeScript     Ruby    JavaScript


• TDD / BDD
•           plugin....
• Query Reviwer....etc
just follow Rails !!
•
•
•
Projects
• 2010/04 : T
• 2010/05 : event
• 2010/08 :                     Digiphoto      event

• 2010/09 : event
• 2010/10 : event
• 2010/11 : T
• 2010/12 :         Digiphoto          event

• 2011/03 : R3
Rails Developer
?
    ...
Rails   ?
            ...
Rapid Development with fun and money
•    Deliver

•                            http://bit.ly/eYfdba




•    (         ) || (    /            )
                             http://bit.ly/dPk7od




•
•
Thanks for listening
http://bit.ly/hDiq72




Burn Rate
http://bit.ly/2UivVg




( Agricola )   Startup / Website
http://blog.xdite.net
Q&A

Rapid development with Rails