Gamadian with Carrierwave
Polymorphic Association & Singe Table Inheritance
2016/09/09 Wei-Yi, Chiu
Outline
Introduce of / How to Carrierwave
What is Polymorphic Association(MTI)
How to Polymorphic Association
What is Single Table Inheritance(STI)
How to STI
「Classier solution for file uploads for Rails 」
–Carrierwave team
選用原因
已經發展超過4年的上傳檔案套件
有完整的add-ons與doc可以隨時加強上傳檔案的功能
e.g) backgrounder, viewer, video-thumbnailer
Tutorialconfig/initializers/carrierwave.rb
What is polymorphic Associations
intro單個關聯裡,model可以屬於多個model
User story - 2
Ethan要從後台傳cover, profile, loadings到s3
一樣要最佳化跟切圖
爲屹希望可以用一張表(assets)管理所有圖片
Tutorialmodels/order_notification.rb
Tutorialmodels/order_notification/short_message_service.rb
Tutorialmodels/order_notification/smart_phone_noti.rb
Tutorial
application.rb
models/order_notification/email_noti.rb
使用時機
Polymorphic當我們擁有多個model共用同一個model時無法使用主鍵(id)有效地select出資料時
STI當我們擁有多個一樣特性的model時使用 主鍵(id)可以有效地select出資料時