iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 16
0
Modern Web

RRRR的世界 (Ruby on Rails + React + Redux)系列 第 16

Day 16, Reading List - Rails的部分

2016最後一天,你回顧2016了嗎?
通常這邊就是規劃DB、規劃Model、然後設定deploy。

好,那就一個一個的來。

DB

基本上,一個作者會有好多本書,然後書會紀錄讀完了沒。
http://ithelp.ithome.com.tw/upload/images/20161231/20103835SLDHREUzq6.png
鏘鏘,就是這樣!

開始generate model

第一個,先產生作者(author)的model:
http://ithelp.ithome.com.tw/upload/images/20161231/201038355YKi97Ob5a.png
很簡單的,只要一個名字欄位,然後記得把它加上has_many

class Author < ApplicationRecord
  has_many :books
end 

再來,generate book的model
http://ithelp.ithome.com.tw/upload/images/20161231/20103835EyAPIQC5Xn.png
欄位多了一點,要記得reference到author。然後編輯model,加上status enum:

class Book < ApplicationRecord
  enum status: [ :unread, :reading, :finished ]
  belongs_to :author
end

setup, migrate!

http://ithelp.ithome.com.tw/upload/images/20161231/20103835Ti6LQep1eM.png

哥先打這樣,我先去煙火卡位。
基本上應該還要加上controller跟TDD,
但我覺得這部分應該再切一天,就是再用掉一天後面TBD的機會。
好囉,大家新年快樂。


上一篇
Day 15, Reading List 假的todo list (切、分工)
下一篇
Day 17, Reading List - Rails部分-2
系列文
RRRR的世界 (Ruby on Rails + React + Redux)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言