ksdg 使用 ruby on rails 快速打造你的 web app
DESCRIPTION
Introduce ruby on railsTRANSCRIPT
自我介紹
Eddie Li米邦國際資訊有限公司 Co-founder
PHP / ZF1 / Web Security / Web Crawler / Ruby on Rails
Blog: adz.visionbundles.comFB: latebird.ticketEmail: [email protected]
Rails 的預設值
1. 使用 coffeescript2. 使用 sass / scss3. pjax 套件 turbolinks4. assets pipline5. scaffold (今天要分享的主題)
找 Gem 的方法請發揮你的想像力
www.ruby-toolbox.comrubygems.org
1. 建好 Migration2. 建好 Model 3. 建好 RESTful style router 到 controller 4. 建好一個 controller + 6 個 actions5. 建好 View
a. index.html.erb - 清單
b. edit.html.erb - 編輯頁面
c. new.html.erb - 新增頁面
… 等等 7. 建好相關 assets file (coffee, scss)8. 其他
Scaffold 幫你做的
一. 把 db schema 納入 code 的版本管理
二. 慣例以 id 當 primary key三. t.timestamp 自動加上 column
a. updated_at => datetimeb. created_at => datetime
git checkout 回任何一個版本 schema 都還在 :)
Migration 1
多一張表 schema_migrations
1. Migration File 以 timestamp 命名
2. 多人開發時,不會因為某個小白改到 schema3. 隨時可以 rake db:rollback 回到上一個 schema 版本
Migration 3
注意事項:a. 非常小心使用
b. commit migration 前,先試試 migrate & rollback 都正常
c. 若沒有使用正常流程可能會有 migrate conflict
Migration 4
Router 定義 resource 後依照 REST Style URL1. 自動對應到 controller 內 7 個 actions2. 自動產生相關的 URL Helper 可以在 View 中使用
Router (Resource)
Model (還不止這樣)
scope - 把 query 拆成有意義的 function,增加 readable & maintainablemixin - 把共用、複雜的 model 拆出來,達到優雅的程式碼 + DRY validator - 把資料驗證邏輯寫在 Model 跟 Form (等等會提)serialize - 讓你的 RDBMS 有一咪咪 Free schema 的感覺
callbacks - 提供 after_create, before_save, ….. 多個 callback
….. 講完可能就明天了
除了有 form_for 的功能外還有:
1. form template - 提供熱門套件 bootstrap … etc2. 綁定 input type - 依照 db column data type3. 其他瑣碎的事 - i18n, hints, label, error message display
更強的 [gem] simple_form
登入認證用的 Gem
1. Devise - 10 分鐘完成你的會員系統
2. omniauth - 提供統一規格界面實作多方認證
omniauth-facebookomniauth-twitteromniauth-github
omniauth-renren omniauth-weibo
有趣的 Gem
1. capybara-webkit - Ruby Webkit Driver
2. faye-websocket - Web Socket Server
3. rubcas-sever - cas protocol 實作的 SSO Server
Ruby / RoR 相關的 Project
1. Gitlab - self hosting github2. Redmine - project management tool3. Selfstarter - crowd-founding
參考至: http://www.opensourcerails.com/
我們需要高手相助
米邦國際資訊有限公司 VisionBundles Int’l Ltd.晚鳥票 / EC 平台 / 網頁遊戲開發
Senior Ruby on Rails Web Developer (一名)Senior F2E (一名)
歡迎您來參加
Group: Kaohsiung Rails Meetup x 讀書會
http://goo.gl/VkkZAb