rails 常见命令 不断补充

(一)常用的
rails s
rails c
rails s -p3001多个端口//
(
rake assets:precompile:all RAILS_ENV=production #产品模式编译
运行之后会在public的assets文件下产生大量静态文件,切换回development时需要删除掉,然后清空缓存,不然会报一些错。
rails s -e production运行产品环境
)
(二)与rake相关的
rails g migration 一般是单独创建一张表或者给某张存在的表进行添加修改删除字段
rails g model model_name会自动创建一个模型以及对应的一张表,可以在里面进行字段信息设置。
rails g migration add_xx_to_xxtbales
def change
    add_column :users, :u_status, :integer, default: 0, :comment=>'审核状态'
  end
修改整个表名
rails g migration rename_xx_to_xx
  def up
  rename_table("odler","new_names")
  end
修改某张表中的字段
rails g migration rename_xxx_for_xxtables
  def up
  rename_column(:projects, :area, :square)
  end
移除某张表中的某个字段
remove_xxx_from_xxtables
  def up
    remove_column :projects, :nature
  end

修改表中某个字段类型
rails g migration change_xx_for_xxtables
  def up
  change_column :notice_infos, :genre, :integer
  end
其实上面修改字段信息为其它名字也可以使用change的方式,但是为了明确到底是change什么还是使用对应的比较好。
(三)
  rake db:migrate迁移
  rake db:rollback回滚如果(二)步中设置了up需要设置down

猜你喜欢

转载自hhg08.iteye.com/blog/2223767