1. 创建外键的时候可以通过 belongs_to xx, index: true 来。 比如:
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! 方法,在更新浏览量之类的很方便。