SlideShare uma empresa Scribd logo
1 de 51
Baixar para ler offline
Ruby on Rails
   Part1:
  ihower@gmail.com




    http://creativecommons.org/licenses/by-nc/2.5/tw/
•              (a.k.a ihower)
    http://ihower.idv.tw/blog/
•              (a.k.a ihower)
        http://ihower.idv.tw/blog/



•
             http://handlino.com
•              (a.k.a ihower)
        http://ihower.idv.tw/blog/



•
             http://handlino.com
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                     10
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             PHP : Rails = 8 : 1
Rails clone
Rails                   ?
                                M




V                 C



            MVC
       Model-View-Control
DB schema
                 Ruby
class CreatePeople < ActiveRecord::Migration
  def self.up
    create_table :people do |t|
      t.string :name
      t.integer :age
      t.date :birthday
      t.text :bio
      t.timestamps
    end
  end

  def self.down
    drop_table :people
  end
end
Active Record
                 ORM

class Person < ActiveRecord::Base
    #
end

person = Person.new
person.name "ihower"
person.age = 18
person.save

person = Person.find(1)
puts person.name #      ihower
Action Controller
            HTTP request


class PeopleController < ApplicationController

  # GET /people
  def index
    @people = Person.all
  end

end
Action Controller
                        HTTP request


            class PeopleController < ApplicationController
method
   action
              # GET /people
              def index
                @people = Person.all
              end

            end
Action Controller
                        HTTP request


            class PeopleController < ApplicationController
method
   action
              # GET /people
              def index
                @people = Person.all
              end
                        instance variable
            end                    View
Action View
                  Ruby          HTML


<html>
  <body>
    <h1>Guestbook</h1>
    <% @people.each do |person| %>
    <p><%= person.name %>: <%= person.bio %></p>
    <% end %>
  </body>
</html>
Why Rails?
 •
 •
 •    (prototyping)

 •
 •
Because Rails is ...
•   MVC                •                              (Ajax
                             RESTful              )
•                      •
•                      •   Ruby               (          )
•   ActiveRecord ORM
                       •          Migration
•            (DRY)
Thank you.



Get to the Point! (http://johnwlong.com/slides/gettothepoint/)
Ruby on Rails slide by thegiive in COSCUP
Delivery of the key adoption Factors and key characteristics of
companies using ruby on rails by Michel Barbosa
Ruby on Rails
   Part2:
  ihower@gmail.com




    http://creativecommons.org/licenses/by-nc/2.5/tw/
README

•
    http://ihower.idv.tw/blog/archives/1743

•
    http://ihower.idv.tw/course/rails.html
Web framework?
•
•                       Perl CGI PHP ASP
                               MVC Database
       URL          Template       Cookie
        Ajax                 ....

•       Framework

    Framework
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
Rails                                   MVC?
                       Routing
           1.
                             2.
                     ActionController


                4.                      3.
   5.

        ActionView                 ActiveRecord




                                             DB
MVC?
•
•
    (DRY: Don’t repeat yourself)
•
Ruby on Rails

• Ruby 1.8.6 1.8.7
• Rubygems (Ruby              )
•           Rails      SQLite 3
  MySQL   Postgres Oracle DB2
  MSSQL
Rails
Hello World!(live demo &   )
(Routes)




http://localhost:3000/welcome/say

                           Controller           Action

# /config/routes.rb
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
Model
(live demo)
ORM ?
•   ActiveRecord     Rails             ORM
•   ORM: Object-Relational Mapping
•                  (table)             (classe)
    •
•                (row)               (object)
    •
•                  (column)                       (object
    attribute)
script/console
ORM        (     )
script/*    ?

• script/about
• script/console
• script/generate
• script/server
• script/plugin
Rake?
•            Make      Ruby
•
    # lib/tasks/my_task.rake
    namespace :my
      desc "task description"
      task :foo_task => :environment do
        puts “foobarrrr”
      end
    end


                         rake my:foo_task
Rake   ?

• rake -T
• rake db:migrate
• rake db:drop
• rake tmp:clear
• rake notes
DB Migration?
•              Ruby                                  (Schema)
•
    •   e.g.                                    ??


•
    •   e.g. SQLite3   MySQL   Postgres...etc


•
                       Migration
Rails
•   app                 •   log
    •     controllers   •   public
    •     helpers
                        •   script
    •     models
                        •   test
    •     views
                        •   tmp
•   config
                        •   vendor
•   db

•   doc

•   lib
Rails environments
•                       development,
    production, test mode
•
•                Log level Session store,
    custom library, Email setting
•          environment
controller             view
             (live demo &   )
controller             view
             (live demo &   )
controller             view
             (live demo &   )
controller             view
             (live demo &   )
Helper ?
•        view template     helper method
    • link_to
    • form_for
    •h  (XSS       )


• /app/helpers/*            Helper
Layout        (live demo &    )




• View                     Layout             HTML


• /app/views/layouts/application.html.erb
flash hash         (live demo &     )




•            flash hash         redirect
    action
•
DRY: Partial template
           (live demo &   )




•   View
•
DRY: before_filter
             (live demo &   )




•   Controller
•         ID       Model
Model Validation
                 (live demo &   )




•         post.rb
    validates_presence_of :title
•       new.html.erb   edit.html.erb
    <%= error_messages_for :post %> helper
Thank you.




Agile Web Development with Rails 3rd.
RailsGuides http://guides.rubyonrails.org

Mais conteúdo relacionado

Mais procurados

Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
_zaMmer_
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang
 
RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3
Anton Narusberg
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3
Henry S
 

Mais procurados (18)

O que há de novo no Rails 3
O que há de novo no Rails 3O que há de novo no Rails 3
O que há de novo no Rails 3
 
Plone for Education: Bibliographies
Plone for Education: BibliographiesPlone for Education: Bibliographies
Plone for Education: Bibliographies
 
PLAT-7 Spring Web Scripts and Spring Surf
PLAT-7 Spring Web Scripts and Spring SurfPLAT-7 Spring Web Scripts and Spring Surf
PLAT-7 Spring Web Scripts and Spring Surf
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
An introduction to Rails 3
An introduction to Rails 3An introduction to Rails 3
An introduction to Rails 3
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
 
RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3
 
OSOM - Ruby on Rails
OSOM - Ruby on Rails OSOM - Ruby on Rails
OSOM - Ruby on Rails
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands Meeting
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
From Java to Ruby...and Back
From Java to Ruby...and BackFrom Java to Ruby...and Back
From Java to Ruby...and Back
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3
 
Ro r trilogy-part-1
Ro r trilogy-part-1Ro r trilogy-part-1
Ro r trilogy-part-1
 

Destaque

Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
Wen-Tien Chang
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
Wen-Tien Chang
 

Destaque (20)

Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
 
Ruby on Rails为什么这么红?
Ruby on Rails为什么这么红?Ruby on Rails为什么这么红?
Ruby on Rails为什么这么红?
 
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]
 
Certbotで無料TLSサーバー
Certbotで無料TLSサーバーCertbotで無料TLSサーバー
Certbotで無料TLSサーバー
 
Rails I18n 20081125
Rails I18n 20081125Rails I18n 20081125
Rails I18n 20081125
 
正規表現の先読みについて
正規表現の先読みについて正規表現の先読みについて
正規表現の先読みについて
 
Ruby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacRuby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for Mac
 
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
 
Sublime Text 2 Tips & Tricks
Sublime Text 2 Tips & TricksSublime Text 2 Tips & Tricks
Sublime Text 2 Tips & Tricks
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
nadoka さんの m17n 対応のベストプラクティス
nadoka さんの m17n 対応のベストプラクティスnadoka さんの m17n 対応のベストプラクティス
nadoka さんの m17n 対応のベストプラクティス
 
hubot-slack v4移行時のハマりどころ #hubot_chatops
hubot-slack v4移行時のハマりどころ #hubot_chatopshubot-slack v4移行時のハマりどころ #hubot_chatops
hubot-slack v4移行時のハマりどころ #hubot_chatops
 
lilo.linux.or.jp を wheezy から jessie にあげた話
lilo.linux.or.jp を wheezy から jessie にあげた話lilo.linux.or.jp を wheezy から jessie にあげた話
lilo.linux.or.jp を wheezy から jessie にあげた話
 
Cognitive APIs and Conversational Interfaces
Cognitive APIs and Conversational InterfacesCognitive APIs and Conversational Interfaces
Cognitive APIs and Conversational Interfaces
 
Python webinar 2nd july
Python webinar 2nd julyPython webinar 2nd july
Python webinar 2nd july
 
程式設計首日封
程式設計首日封程式設計首日封
程式設計首日封
 
淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事
 

Semelhante a Ruby on Rails : 簡介與入門

Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
_zaMmer_
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
SVDevOps
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
Ricardo Sanchez
 
[.Net开发交流会][2010.06.19]better framework better life(吕国宁)
[.Net开发交流会][2010.06.19]better framework better life(吕国宁)[.Net开发交流会][2010.06.19]better framework better life(吕国宁)
[.Net开发交流会][2010.06.19]better framework better life(吕国宁)
Shanda innovation institute
 
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
Takayuki Kyowa
 

Semelhante a Ruby on Rails : 簡介與入門 (20)

Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Upgrading to rails3
Upgrading to rails3Upgrading to rails3
Upgrading to rails3
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
 
[.Net开发交流会][2010.06.19]better framework better life(吕国宁)
[.Net开发交流会][2010.06.19]better framework better life(吕国宁)[.Net开发交流会][2010.06.19]better framework better life(吕国宁)
[.Net开发交流会][2010.06.19]better framework better life(吕国宁)
 
Better Framework Better Life
Better Framework Better LifeBetter Framework Better Life
Better Framework Better Life
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Demystifying Ruby on Rails
Demystifying Ruby on Rails Demystifying Ruby on Rails
Demystifying Ruby on Rails
 
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
 
Better framework, better life
Better framework, better lifeBetter framework, better life
Better framework, better life
 
Rails 3.1
Rails 3.1Rails 3.1
Rails 3.1
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Rhodes
RhodesRhodes
Rhodes
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 
Bhavesh ro r
Bhavesh ro rBhavesh ro r
Bhavesh ro r
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 

Mais de Wen-Tien Chang

Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
Wen-Tien Chang
 
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Wen-Tien Chang
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in Ruby
Wen-Tien Chang
 
從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事
Wen-Tien Chang
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
Wen-Tien Chang
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
Wen-Tien Chang
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
Wen-Tien Chang
 
A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0
Wen-Tien Chang
 
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
Wen-Tien Chang
 
RubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & ClosingRubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & Closing
Wen-Tien Chang
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-Tien Chang
 

Mais de Wen-Tien Chang (20)

⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛
 
A brief introduction to Machine Learning
A brief introduction to Machine LearningA brief introduction to Machine Learning
A brief introduction to Machine Learning
 
RSpec on Rails Tutorial
RSpec on Rails TutorialRSpec on Rails Tutorial
RSpec on Rails Tutorial
 
RSpec & TDD Tutorial
RSpec & TDD TutorialRSpec & TDD Tutorial
RSpec & TDD Tutorial
 
ALPHAhackathon: How to collaborate
ALPHAhackathon: How to collaborateALPHAhackathon: How to collaborate
ALPHAhackathon: How to collaborate
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in Ruby
 
從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0
 
RubyConf Taiwan 2012 Opening & Closing
RubyConf Taiwan 2012 Opening & ClosingRubyConf Taiwan 2012 Opening & Closing
RubyConf Taiwan 2012 Opening & Closing
 
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
 
Git Tutorial 教學
Git Tutorial 教學Git Tutorial 教學
Git Tutorial 教學
 
RubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & ClosingRubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & Closing
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 
RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試
 

Ruby on Rails : 簡介與入門

  • 1. Ruby on Rails Part1: ihower@gmail.com http://creativecommons.org/licenses/by-nc/2.5/tw/
  • 2. (a.k.a ihower) http://ihower.idv.tw/blog/
  • 3. (a.k.a ihower) http://ihower.idv.tw/blog/ • http://handlino.com
  • 4. (a.k.a ihower) http://ihower.idv.tw/blog/ • http://handlino.com
  • 5. Rails? • ( MIT ) Web database-backed • MVC (Model-View-Control ) • ( ) Ruby Ajax ORM (object-relational-mapping) • 2004 David Heinemeier Hanson(DHH) 37signals
  • 6. Ruby • Don’t Repeat Yourself (DRY) • • • Convention Over Configuration • •
  • 7. Ruby on Rails ? • ( ) • ( Joomla Durpal CMS •
  • 8. Rails • 2005 DHH Hacker • 2006 Rails Jolt • 2005~2006 Ruby/Rails 1552% • Ruby Tiobe 26 10
  • 9. Rails ? Java(Spring/Hibernate) Rails 4 20 4 ( 5 ) 3293 1164 1161 113 / 62/549 55/126 Justin Gehtland Java Rails
  • 10. Rails ? • Justin Gehtland Java :Rails = 3.5 : 1 • Proc.net PHP : Rails = 10 : 1 • JavaEye JAVA : Rails = 10 : 1 • thegiive PHP : Rails = 8 : 1
  • 12. Rails ? M V C MVC Model-View-Control
  • 13. DB schema Ruby class CreatePeople < ActiveRecord::Migration def self.up create_table :people do |t| t.string :name t.integer :age t.date :birthday t.text :bio t.timestamps end end def self.down drop_table :people end end
  • 14. Active Record ORM class Person < ActiveRecord::Base # end person = Person.new person.name "ihower" person.age = 18 person.save person = Person.find(1) puts person.name # ihower
  • 15. Action Controller HTTP request class PeopleController < ApplicationController # GET /people def index @people = Person.all end end
  • 16. Action Controller HTTP request class PeopleController < ApplicationController method action # GET /people def index @people = Person.all end end
  • 17. Action Controller HTTP request class PeopleController < ApplicationController method action # GET /people def index @people = Person.all end instance variable end View
  • 18. Action View Ruby HTML <html> <body> <h1>Guestbook</h1> <% @people.each do |person| %> <p><%= person.name %>: <%= person.bio %></p> <% end %> </body> </html>
  • 19. Why Rails? • • • (prototyping) • •
  • 20. Because Rails is ... • MVC • (Ajax RESTful ) • • • • Ruby ( ) • ActiveRecord ORM • Migration • (DRY)
  • 21. Thank you. Get to the Point! (http://johnwlong.com/slides/gettothepoint/) Ruby on Rails slide by thegiive in COSCUP Delivery of the key adoption Factors and key characteristics of companies using ruby on rails by Michel Barbosa
  • 22. Ruby on Rails Part2: ihower@gmail.com http://creativecommons.org/licenses/by-nc/2.5/tw/
  • 23. README • http://ihower.idv.tw/blog/archives/1743 • http://ihower.idv.tw/course/rails.html
  • 24. Web framework? • • Perl CGI PHP ASP MVC Database URL Template Cookie Ajax .... • Framework Framework
  • 25. MVC? • Model Controller View • Model • • View • Ruby HTML • Controller Model • (e.g. ) Request Model View (e.g. HTML)
  • 26. 1. Controller 2. 3. 4. View Model DB
  • 27. Rails MVC? Routing 1. 2. ActionController 4. 3. 5. ActionView ActiveRecord DB
  • 28. MVC? • • (DRY: Don’t repeat yourself) •
  • 29. Ruby on Rails • Ruby 1.8.6 1.8.7 • Rubygems (Ruby ) • Rails SQLite 3 MySQL Postgres Oracle DB2 MSSQL
  • 31. (Routes) http://localhost:3000/welcome/say Controller Action # /config/routes.rb map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format'
  • 33. ORM ? • ActiveRecord Rails ORM • ORM: Object-Relational Mapping • (table) (classe) • • (row) (object) • • (column) (object attribute)
  • 35. script/* ? • script/about • script/console • script/generate • script/server • script/plugin
  • 36. Rake? • Make Ruby • # lib/tasks/my_task.rake namespace :my desc "task description" task :foo_task => :environment do puts “foobarrrr” end end rake my:foo_task
  • 37. Rake ? • rake -T • rake db:migrate • rake db:drop • rake tmp:clear • rake notes
  • 38. DB Migration? • Ruby (Schema) • • e.g. ?? • • e.g. SQLite3 MySQL Postgres...etc • Migration
  • 39. Rails • app • log • controllers • public • helpers • script • models • test • views • tmp • config • vendor • db • doc • lib
  • 40. Rails environments • development, production, test mode • • Log level Session store, custom library, Email setting • environment
  • 41. controller view (live demo & )
  • 42. controller view (live demo & )
  • 43. controller view (live demo & )
  • 44. controller view (live demo & )
  • 45. Helper ? • view template helper method • link_to • form_for •h (XSS ) • /app/helpers/* Helper
  • 46. Layout (live demo & ) • View Layout HTML • /app/views/layouts/application.html.erb
  • 47. flash hash (live demo & ) • flash hash redirect action •
  • 48. DRY: Partial template (live demo & ) • View •
  • 49. DRY: before_filter (live demo & ) • Controller • ID Model
  • 50. Model Validation (live demo & ) • post.rb validates_presence_of :title • new.html.erb edit.html.erb <%= error_messages_for :post %> helper
  • 51. Thank you. Agile Web Development with Rails 3rd. RailsGuides http://guides.rubyonrails.org