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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ruby on rails探索

583
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
583
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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