Ruby on rails探索
Upcoming SlideShare
Loading in...5
×
 

Ruby on rails探索

on

  • 692 views

 

Statistics

Views

Total Views
692
Views on SlideShare
692
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

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

Ruby on rails探索 Ruby on rails探索 Presentation Transcript

  • Ruby on Rails 探索 kewang
  • Agenda● What is Ruby?● What is Rails?● Live DEMO● FAQ● Q&A 2
  • What is Ruby? 鑽石恆久遠,一顆就破產 3
  • What is Ruby?● 開放原碼、物件導向的動態直譯式程式語言● 簡單哲學、高生產力● 精巧、自然的語法● 靈感來自 Lisp, Perl, Smalltalk● 設計的目的是要讓程式設計師 Happy 4
  • Matz 說● 一般程式語言的開發目的 ● 可寫出能夠高速運作的程式 ● 可在短期間學會寫程式 ● 寫一次到處都能跑 ● 小朋友也能輕易寫出程式 5
  • 但主張「讓寫程式更快樂」的語言卻不太常見 6
  • MatzRuby is simple in appearance, but is verycomplex inside, just like our human body. 7
  • Programming Language Type● Dynamic Strong Language ● Ruby ● Perl ● Python● PHP is Dynamic, but is not Strong.● Java is Strong, but is not Dynamic. 8
  • EVERYTHING IS OBJECT 9
  • irb – Interactive Ruby 10
  • TIOBE Ranking 11
  • Features● Iterator● Code block (closure)● ! and ?● Meta-programming 12
  • Iterator● 重複做多次類似的事情● upto, downto, step, times, collect, map, each_*, *_each, sort...many methods 13
  • Code block (closure) 14
  • Code block (closure) 15
  • Code block (closure) 16
  • Code block (closure) 17
  • ! and ?● ! means side-effect● ? means return Boolean 18
  • ! and ? 19
  • Meta-programming 20
  • RubyGems● Ruby 的套件管理工具● 所有的 Ruby 套件都可以用 gem 安裝 ● Rails ● RMagick ● Heroku ● ...etc.● http://rubygems.org 21
  • Sinatra● Its a VERY lightweight web development package● gem install sinatra● http://www.sinatrarb.com 22
  • Hello Sinatra● ruby myapp.rb, and open http://localhost:4567 23
  • Hello Parameter 24
  • Sinatra - XDite 如是說 使用 Sinatra 的目的並不是用來開發那些巨型 的 Web application ,而是搭造那些小型的應 用程式或者 API 介面。這樣做有些什麼好處 呢? 如果你只是想寫一支小型程式,或者開發 API ,並不需要使用 Rails 這麼複雜 ( 或肥 ) 的 Framework 做這些簡單的事。使用 Sinatra 既簡單, Respond 也迅速。 25
  • What is Rails? 火車環島正夯 26
  • What is Rails?● Its a Web Framework 27
  • What is Rails? 28
  • What is Rails? ● DHH ● 從 37signals 公司的專案 管理工具 Basecamp 裡面 分離出 Ruby on Rails ● 2005 年獲得年度最佳 Hacker 29
  • What is Rails?● 正式名稱 Ruby on Rails● 使用 MVC(Model-View-Control)● 內建 unit / integration test● 支援 Ajax, RESTfFul, ORM● 支援最新技術 HTML5, jQuery, SASS, HAML, Coffee Script 30
  • Design Principles DRYDont Repeat Yourself 31
  • Design Principles CoCConvention over Configuration 32
  • Rails is so FAST!!! JSP Rails 4 個月,每週約 20 4 個晚上,每晚 5 小 交貨時間 小時 時 程式碼行數 3293 1164 設定檔行數 1161 113類別數 / 方法數 62/549 55/126 33
  • What is MVC 34
  • What is MVC● Model 包裝了資料與商業邏輯,例如操作資料庫● View 表示使用者介面,顯示及編輯表單● Controller 將資料送進送出 Model ,處理從外界 來的 HTTP Request ,與 Model 互動後輸出至 View 35
  • DB schema 36
  • ActiveRecord (M) 37
  • Rails console 38
  • Rails console 39
  • ActionController (C) 40
  • ActionView (V) 41
  • What is URL routing? 42
  • a bloated controller class EventController < ApplicationControllerindex /events/indexshow /events/show/1new /events/newcreate /events/createshow_comment /events/3/show_comment/6mark_spamcomment /events/7/mark_spamcomment/5add_favorite /events/2/add_favoriteinvite /events/1/invitedeny_user /events/1/deny_user/13allow_user /events/2/allow_user/27 43
  • What is RESTful? before after ActionController/events/create POST /events events#create/events/show/1 GET /events/1 events#show/events/update/1 PUT /events/1 events#update/events/destroy/1 DELETE /events/1 events#destroy 44
  • Lets modify bloated controller class EventController < ApplicationControllerindex GET /events events#indexshow GET /events/1 events#shownew GET /events/new events#newcreate POST /events events#createshow_comment GET /events/3/comments/6 event_comments#showmark_spamcomment PUT /events/7/comments/5/spam event_comments#spamadd_favorite POST /events/2/favorite events#favoriteinvite POST /events/1/invite events#invitedeny_user PUT /events/1/users/13/deny event_users#denyallow_user PUT /events/2/users/27/allow event_users#allow 45
  • RESTful routingHTTP Verb Path actionGET /photos indexGET /photos/new newPOST /photos createGET /photos/:id showGET /photos/:id/edit editPUT /photos/:id updateDELETE /photos/:id destroy 46
  • One action, multiple formats 47
  • One action, multiple formats 48
  • Live DEMO...Never Live DEMO 49
  • FAQFxxk you!? 50
  • Why Ruby?● Domain-specific language● Full object-oriented programming● High usability● High readability, maintenance 51
  • Why Rails?● The most successful Web Framework● Imitation is the greatest compliment ● CakePHP ● Grails ● TurboGears ● catalyst 52
  • Websites 53
  • Performance Comparison PHP 5.2.3 Python 2.5.1 Lines of Code Time per iterationLanguage Ruby 1.9.0 (microseconds) C++ 4.2.3 Java 1.6 0 100 200 300 400 500 600 700 54 愈小愈好
  • Performance is slow?● 如果一個框架可以讓你僅變快 20% ,或許你應該 繼續使用比較保險的語言,像是 Java 。但是如果 你可以變快 300% 甚至更高,那麼其他的差異都 變的不重要了 from Beyond Java 55
  • Q&AQuick Asleep 56