SlideShare a Scribd company logo
Ruby on Rails
    BY thegiive




                  ( License by CC   2.0 )
About me

•       ID : thegiive
• SocialPicks.com
•       Ruby on Rails
• Blog : http://lightyror.thegiive.net/
• Email : thegiive at gmail . com
Outline

•             Ruby on Rails
• Ruby on Rails
• Rails
• Active Record
•
• Active Record
Ruby on Rails

                    A
95.00

71.25

47.50
                                                             C
                                        B
23.75

   0
        6   7   8       9     10   11       12   1   2   3       4
A


95.00

71.25

47.50

23.75

   0
        6   7   8   9   10   11   12   1   2   3   4
Before Rails day

                  10%
•   PHP
•
•                       90%
After Rails day
                                  Survey    Bloging


•        2
              PHP               10%
    Project
                          20%              40%
•
•                               30%
Phone time project

•       “
            “


•       20      code
•   3
Ruby on Rails in UbiSunrise
B


95.00

71.25

47.50

23.75

   0
        6   7   8   9   10   11   12   1   2   3   4
•
•
    •
    •
    •
Coding        RD




Rails




PHP



        0   25   50            75        100
Ruby on Rails in UbiSunrise
C


95.00

71.25

47.50

23.75

   0
        6   7   8   9   10   11   12   1   2   3   4
PS2   10
After PS2 Day
                          Blog          Survey
              PS2




•                   20%
•                                 30%
    Project
•
              30%                 10%
                            10%
Ruby on Rails in UbiSunrise
Ruby on Rails

• MVC
• Ruby
• DHH       Basecamp
 Project
• David Heinemeier Hansson
•           DHH
•        26




                             DHH Blog
How Hot is Rails

• Rails 2006     400
          150     24
• 2005 Ruby on Rails
  1500% 2006                700%
• Ruby                 26          13
Rails Clone
•
JAVA (Spring/Hibernate)        Rails
               4           (20       /       )4   (5       /)
                            3293                   1164

                            1161                   113

Class/method               62/549                 55/126


        Justin Gehtland              Blog
• RD
•
•
•        Web Site
• Performance
Ruby on Rails in UbiSunrise
(


•
•
•   PS2
• Justin Gehtland JAVA : Rails = 3.5 : 1
•           Java : Rails = 25 : 1
• Proc.net PHP : Rails = 10 : 1
• JavaEye            JAVA : Rails = 10 : 1
•                  PHP : Rails = 8 : 1

       http://lightyror.blogspot.com/2006/10/rails.html
Rails
• ORM
• Convention over Configuration
• Don’t Repeat Yourself
• Domain Specific Language
ORM


• Object Relational Mapping
•
• Propel Hibernate Active Record ...
Convention over Configuration

                   <?xml version="1.0" encoding="UTF-8"?>
                   <!DOCTYPE hibernate-mapping

•
                   PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
                   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.d
                   <hibernate-mapping>
                   <class name="test.hibernate.Order" table="orders">
                   <id name="id" type="string" unsaved-value="null" >
                   <column name="id" sql-type="integer" not-null="true"/>
                   <generator class="native"/>

•                  </id>
                   <key column="order_id" />
                   <one-to-many class="test.hibernate.OrderItem" />
                   </set>
                   </class>
                   </hibernate-mapping>
DRY


• Don’t Repeat Yourself
• View         Helper Partial    DRY
• Controller        Module Lib         DRY
Domain Specific Language

• Ruby               DSL
• Rails DB-Driven Web App DSL
 • has_one , has_many , HABTM
 •           symbol ( :abc )
Migration

create_table :stores do |t|
  t.column :name , :string
  t.column :info , :text
  t.column :open_time , :string
  t.column :user_id , :integer
  t.column :created_at , :datetime
  t.column :updated_at , :datetime
 end
Active Record

• Rails
•                 ORM
• Convention over Configuration
•          1:1 1:m n:m
•       MySQL SQL Server Oracle
  SQLite
ORM Example
                     a = People.new
     People
   id        int    a = People.find(1)
 name     varchar
 phone    varchar   a.name = ‘David’
address     text        a.destroy
  sex      enum
                         a.save
Relation Table Example
                               Article
     People
   id        int        id               int
 name     varchar   person_id            int
 phone    varchar      title        varchar
address     text
                     content             text
  sex      enum
                    created_at datatime
Relation ORM
a = People.find(1)

a.articles


a.articles.find(:first)


a.articles << Article.new(...)
Person a
•
•
• Legacy
• Template
“          	
      	
  	
           	
 
                    ”           JAVA
    	
 
                  Python Perl
Rails


•                  .....   ....
    • DHH                  Ruby
    • Ruby   DSL
    •
    •
“                      20%
                          JAVA
     300%
                         ”

    From Beyond Java
Ruby on Rails in UbiSunrise
Ruby          ?

•
    Ruby Programmming
• Ruby is not Rails
• Rails       Ruby 60%
City                        Neighbor
 id           int                city_id           int
                            neighbor_id            int
name      varchar


                                  “        “   ”
                    “   ”    “
• city            n:m   neighbor
     join table
•
•
function     (A       B        {

 if( B      A            ){

 
 return ‘    ’
	 }else{

 
 for ( A                            C   {

 
 
 if( B       C                {

 
 
 
 return ‘      ’
			}
		}

 
 return ‘    ’
                           Pseudo Code
	}
}
def check ( city_a , city_b )
	 if ( city_a.neighbors.include?(city_b)

 
 return ‘       ’
	 else
	 	 city_a.neighbors.each do | neighbor_of_a |
	 	 	 if (neighbor_of_a.neighbors.include?(city_b) )

 
 
 
 return ‘         ’
	 	 	 end
	 	 end

 
 return ‘       ’
                                    Rails Code
	 end
end
Ruby on Rails in UbiSunrise
•   Ubi
•    Topic
•
RoR * 1hr


RoR in pratice * 3hr
Ruby on Rails in UbiSunrise
•
•    10
•
•   Demo Code
•
•
• Inspire by
Code Stats

• Code 270
• 230
•          40
• 80%
•
• Tag
• Urmap
• Search
•
Outline
•
•
•
•
• Urmap API
• Tag
Ruby on Rails in UbiSunrise
Live Demo RoR


•
•
• Contagions
Demo
Ruby on Rails in UbiSunrise
• Live Demo With Subversion
•       reversion
• May the force be with me
Stores
 Users                       id     int
id   int                  user_id int


              Comments
              id    int
           user_id  int
           store_id int
code



• svn Committed revision 9.
Ruby on Rails in UbiSunrise
•
• Yullio Mollio plugin for Rails
•            layout
• script/generate layout_yullio stores sidebar
•            Rails
code


• svn Committed revision 10.
•      sidebar         : 11
•      Store Layout : 12
•              Plugin
• session
• before_filter
•
•
code


• User   : 13
•        : 14
• Rmagick
•
•
file_column


• Base on Rmagick
•          Rails
• Upload
code



•   : 15
• Search Engine + Web API
• Solr + act_as_solr
• Ferret + ast_as_ferret
SQL Search


• Like ‘%....%’
•                 SQL code
• Rails SQL
code


• Committed revision 16.
•       partial template
Urmap API

•
•
• UrMap API
•
    • “ Hello       25   121
                “
    •           GPS
•
Ruby on Rails in UbiSunrise
...
Ruby on Rails in UbiSunrise
Ruby on Rails in UbiSunrise
Cron Script


•      ActiveRecord
• Ruby HTTP POST
code



• Commit reversion 17
Table Relationship


• Active Record
•           console   relationship
code


• Commit reversion 18
• ruby script/console
Comment


•
•
code



• Commit reversion 19
Tag


• ast_as_taggable
• model.tag_with('red library book')
• model.tags
code


• Committed revision 20.
•              Committed revision 21
•
•
•
?
?
Q A

More Related Content

Ruby on Rails in UbiSunrise