生成 Controller (route views helpers assets)
rails generate controller Welcome index
查看路由
rails routes
生成 Model
rails generate model Article title:string text:text
生成 Mailer
rails generate mailer UserMailer
创建 Database与表
rails db:create
rails db:migrate
删除已创建表
class CreateUsers < ActiveRecord::Migration[5.1] def change drop_table :users # delete table before create create_table :users do |t| t.string :name t.string :email t.string :password_digest t.timestamps end endend
向Database 中已存在表添加 Column
rails g migration AddAuthTokenToUsers auth_token:string
db/migrate/20180302143136_add_auth_token_to_users.rb
class AddAuthTokenToUsers < ActiveRecord::Migration[5.1] def change add_column :users, :auth_token, :string endend
向Database 中已存在表删除 Column
class ChangeThingsInComments < ActiveRecord::Migration[5.1] def change add_column :comments, :user_id, :integer remove_column :comments, :username remove_column :comments, :email endend