intro_rails

一些小技巧

1. 创建外键的时候可以通过 belongs_to xx, index: true 来。 比如:

create_table :orders do |t|
  t.belongs_to :customer, index: true
  t.datetime :order_date
  t.timestamps null: false
 end

2.Rails 内置 increment! 方法,在更新浏览量之类的很方便。