Ruby on Rails
ihower@gmail.com
   Ruby Taiwan
2010/5@
Agenda

• Who am I
• My story about web development
• Introduction to Rails
• Rails on Rails live demo
• Why Ruby?
Who am I?

•        (a.k.a. ihower)

•
•                    &       (   )


• Ruby on Rails            (since 2006)
http://ihower.tw/blog/
http://twitter.com/ihower
http://ruby.tw
Ruby Tuesday Meetings
http://rubyconf.tw
Where am I?
Software




Desktop    Mobile    Web
Web application



                                Ruby
Java/.NET                PHP   Python
                                Perl
My story about
web development
1990
Tim Berners-Lee
  World Wide Web
1999

•
•   M$ FrontPage         (   !)


•                  CGI
2003
•   Perl CGI

•
CGI, Perl
                           HTML
#!/usr/bin/perl

open(FILE, "count.txt");
$num = <FILE>; $num++;
close (FILE);

open(WRITETO, ">count.txt");
print WRITETO "$num";
close (WRITETO);

print <<PRINTAREA;
content-type:text/htmlnn
<style>
<!--
body {background-color: black; line-height:1;
margin-top: 0cm;
margin-left: 0cm;
margin-right: 0cm}
--></style>
<body><center>
<b><font size=1 color=white>
$num</font></b>
PRINTAREA
2002~2004


•       Dreamweaver

•                     PHP4
    & MySQL
PHP
                   HTML

<?php
$counter = intval(file_get_contents("counter.dat")) + 1;
$fp = fopen("counter.dat", "w");
fwrite($fp, $counter);
fclose($fp);
?>

<p>Visitors: <?php echo @counter %></p>
PHP & MySQL
<?php

	 	    $db = mysql_connect("localhost", "root", "password");
	 	    mysql_query("SET NAMES 'utf8'");
	 	    mysql_select_db($SERVER['db']);
?>
<html>
         <?
	 	       $sql="select * from news where Class='1' or Class='3' order by CTDate desc
limit 0,5";
	 	       $result= mysql_query($sql);
	 	       while ( $arr=mysql_fetch_array($result) ) {
               echo <<<NEWSEND
	 	    <div class="box">
	        	     <span class="box-title-1"> <b> $arr[Title] </b> $arr[CTDate] </span>
	 	         	 <div class="box-content">
	 	    	      $arr[Text]
            	 </div>
	 	    </div>
NEWSEND;
	 	    }
	 	      ?>
</html>
2003 (   )
PHP sucks!
2005
•   PHP web framework

•
Web framework?

• MVC
• ORM
• URL   Template   Session
        Ajax         ......
MVC
•
          Model       Controller View
•    Model
    •
•    View
    •        Ruby     HTML


•    Controller                                Model
    •         (e.g.     )    Request   Model      View (e.g. HTML)
1.
                 Controller

                              2.
            3.
4.

     View                     Model




                                      DB
MVC?
•
•
    (DRY: Don’t repeat yourself)
•
ORM

   • Object-relational mapping
   •
@posts = Post.find(:all, :order => "id desc", :limit => 5 )
@posts.each do |post|
    ...
end
ORM?

• SQL
• ORM
        routine     SQL

•
•                 SQL
2006
•   Ruby on Rails

•
Rails?
•                (   MIT   )   Web
      database-backed

•   MVC (Model-View-Control )

•   (        )             Ruby
    Ajax                          ORM (object-relational-mapping)


•   2004      David Heinemeier Hanson(DHH)
    37signals
•   Ruby

•   Don’t Repeat Yourself (DRY)    •
•   Convention Over Configuration
                                   •
                                   •
                                   •
Ruby on Rails            ?
•                             (

                 )




•   (   Joomla       Durpal
                                  CMS

•
Rails
•   2005   DHH                    Hacker

•   2006   Rails      Jolt

•   2005~2006     Ruby/Rails
                1552%

•   Ruby             Tiobe
      26                     11
Rails                                        ?
          Java(Spring/Hibernate)        Rails


          4               20        4    (       5   )


                  3293                  1164


                  1161                   113


 /               62/549                 55/126


     Justin Gehtland         Java
                           Rails
Rails                                                  ?

•   Justin Gehtland              Java :Rails = 3.5 : 1

•   Proc.net            PHP : Rails = 10 : 1

•   JavaEye                   JAVA : Rails = 10 : 1

•   thegiive(   Rails     )                 PHP : Rails = 8 : 1
Rails clone
Rails                   ?
                                M




V                 C



            MVC
       Model-View-Control
Rails live demo
Creating a weblog in 15 minutes
User stories

•
•
•
•
Why Ruby?
Ruby?
•
    (interpreted)

•
•
•                        a.k.a. Matz
    •           Lisp, Perl,   Smalltalk

    •                                     Happy
a trivial Ruby example


 str = "May Ruby be with you!"
 5.times { puts str }
the example tells us:

•        (typing)

•
•        (code block)
code lines matters
1. more code more bugs
2. more code needs IDE
3. more code needs more time to read
Fred Brooks’ law
“programmer generate about same
amount of code per day regardless
        of the language”
•   Web framework like Rails has
    •   MVC
    •   ORM
•   Ruby is
    •   interpreted scripting language
    •   dynamic typing language
    •   object oriented programming
Rails   Ruby

http://ihower.tw/training
One more thing...
If I were a college
      student...
1. Learn more
programming language
   Scripting Language: Ruby, Python, JavaScript
Functional Language: Erlang, Scala, Haskell, Clojure
2. Master Unix
command Line
3. Use Mac or Ubuntu
     Windows   Unix-like
4. Learn Git or Hg
         :
Live demo
(       )
5. Learn OOP
6. Be Agile
       ?
http://ihower.tw/blog/archives/1750
:




http://local.joelonsoftware.com/wiki/The_Joel_on_Software_Translation_Project:
7. Learn SQL
8. Learn HTTP
9.
Conference & Meetings
• Ruby Tuesday meeting (        )

• RubyConf Taiwan (2010/4/25)
• OSDC.TW (2010/4/24)
• COSCUP (2010/8/14)
• RubyKaigi (2010/8/27 )
ihower

http://ihower.tw/blog/books
遇見 Ruby on Rails

遇見 Ruby on Rails