安裝 Rails (Rails Girls 官方文件)
妳的第一個 Rails App (Rails Girls 官方文件)
安裝 slim-rails / semantic-rails / compass-rails / ...
依照官方文件打 gem 指令安裝
在 gemfile 加入官方文件的設定
指令 bundle install
使用 slim-rails
把 .html.erb 檔名改成 .html.slim
讓輸出的 html 排版便於 debug
slim pretty output: http://stackoverflow.com/questions/17291030/rails-slim-source-output
dev / production / test 三種不同環境有各自的最佳設定,比方說開發環境需要輸出好看的 html 方便 debug,但是上線環境不要,所以 slim pretty output 的設定只寫在 config > environment > development.rb 裡面
設定 css 檔案的順序
app/assets/stylesheets/application.css 中
*= require ’semantic-ui’
*= require ’global’
*= require_self
*= require_tree (相對路徑)
*/
設定 js 檔的順序
原理同上
//= require turbolinks
更改專案名稱
folder name 直接改就可以了
code name 在 config > application.rb 裡面,通常習慣跟 folder name 一樣,但要分開也行…後來我放棄改 code name 了因為好像要改很多地方,怕爛掉 XD
module G0vtoday
config.time_zone = ’Taipei’
config.i18n.default_locale = :"zh-TW"
建立多對多關連
rails g migration (migration名稱,英文,字串,習慣用底線隔開,他會自動幫我們轉成 camel type)
到 timestamp_name.rb 裡面
def change
create_table :sessions_speakers do |t|
t.references :session
t.references :speaker
end
end
指令 rake db:migrate
到 model > speaker.rb
has_and_belongs_to_many :sessions
到 model > session.rb
has_and_belongs_to_many :speakers
migration
資料庫的設定檔
rake db:migrate
讓 migration 設定檔生效
model > xxx.rb
裡面放資料庫關連、自訂對資料庫的操作、驗證、儲存或刪除後要多做哪些事情(callback)
model 裡面純粹的 column 會自動對應到,所以增加欄位不用改,只有增加 relation 的時候需要額外改 model 的 .rb 檔
時段、子時段 (STI)
http://blog.thirst.co/post/14885390861/rails-single-table-inheritance
為什麼 rails new 以後要 bundle install
為什麼 bundle install 以後要 rake db:migrate
為什麼 rails generate scaffold 以後要 rake db:migrate
class Xxxx < ActiveRecord::Base 的意思是…
class
Xxxxx
<
ActiveRecord::Base
::