Ruby on rails 新手学习第三天

Ruby on rails 新手学习第三天

学习资料:
https://sg552.gitbooks.io/happy_book_rails/content/part3_rails_premier/rails_tutorial_from_view.html
https://www.bilibili.com/video/BV1RJ411W7N3?p=1

学习目标:
管理员后台的实现以及数据的增删改查

学习内容:
rails g controller admin::users
Ruby on rails 新手学习第三天

常见的migration方法
注: 以下方法都写在up, down 或者change方法中.
create_table
例如, 创建表 ‘students’ :
create_table :students do |t|
t.string :chinese_name
t.integer :age
t.timestamps
end
drop_table
例如,删掉表’students’ :
drop_table :students
add_column
例如, 向’students’ 表中,增加一个列’name’, 它的类型是字符串:
add_column :students, :name, :string
remove_column
例如, 从’students’ 表中,删除列’name’:
remove_column :students, :name
rename_column
例如, 把’students’ 表的’chinese_name’列, 重命名为 ‘zhong_wen_ming_zi’:
rename_column :students, :chinese_name, :zhong_wen_ming_zi
add_index
例如, 把’students’表的name列建立索引:
add_index :students, :name
remove_index
例如, 把’students’表的已经存在的name索引删掉:
remove_index :students, :name