More Related Content Similar to Ksdg 使用 ruby on rails 快速打造你的 web app (20) Ksdg 使用 ruby on rails 快速打造你的 web app1. 使用 Ruby on Rails
快速打造你的 Web APP
http://goo.gl/Z7ID5I
11. Rails 的預設值
1. 使用 coffeescript
2. 使用 sass / scss
3. pjax 套件 turbolinks
4. assets pipline
5. scaffold (今天要分享的主題)
18. 1. 建好 Migration
2. 建好 Model
3. 建好 RESTful style router 到 controller
4. 建好一個 controller + 6 個 actions
5. 建好 View
a. index.html.erb - 清單
b. edit.html.erb - 編輯頁面
c. new.html.erb - 新增頁面
… 等等
7. 建好相關 assets file (coffee, scss)
8. 其他
Scaffold 幫你做的
19. 一. 把 db schema 納入 code 的版本管理
二. 慣例以 id 當 primary key
三. t.timestamp 自動加上 column
a. updated_at => datetime
b. created_at => datetime
git checkout 回任何一個版本 schema 都還在 :)
Migration 1
23. Router 定義 resource 後依照 REST Style URL
1. 自動對應到 controller 內 7 個 actions
2. 自動產生相關的 URL Helper 可以在 View 中使用
Router (Resource)
27. 應用場景: 1 to 1 關聯
(如一個 user 關聯到一個 profile)
Router (Single Resource)
29. Model (用物件方式存取 db 資料)
Table Column 宣告成 Attribute & Dirty Objects (instance method)
32. Model (還不止這樣)
scope - 把 query 拆成有意義的 function,增加 readable & maintainable
mixin - 把共用、複雜的 model 拆出來,達到優雅的程式碼 + DRY
validator - 把資料驗證邏輯寫在 Model 跟 Form (等等會提)
serialize - 讓你的 RDBMS 有一咪咪 Free schema 的感覺
callbacks - 提供 after_create, before_save, ….. 多個 callback
….. 講完可能就明天了
40. 除了有 form_for 的功能外還有:
1. form template - 提供熱門套件 bootstrap … etc
2. 綁定 input type - 依照 db column data type
3. 其他瑣碎的事 - i18n, hints, label, error message display
更強的 [gem] simple_form
43. 登入認證用的 Gem
1. Devise - 10 分鐘完成你的會員系統
2. omniauth - 提供統一規格界面實作多方認證
omniauth-facebook
omniauth-twitter
omniauth-github
omniauth-renren
omniauth-weibo
44. 有趣的 Gem
1. capybara-webkit - Ruby Webkit Driver
2. faye-websocket - Web Socket Server
3. rubcas-sever - cas protocol 實作的 SSO Server
45. Ruby / RoR 相關的 Project
1. Gitlab - self hosting github
2. Redmine - project management tool
3. Selfstarter - crowd-founding
參考至: http://www.opensourcerails.com/
46. Rails 相關 SaaS
1. Code Climate - code review 工具
2. New Relic - server & app monitor