Active Record 数据迁移

1.创建controler: welcome ;action: index

$ rails generate controller welcome index

2.创建名为Article的model定义title:string text:text
$ bin/rails generate model Article title:string text:text 
$ bin/rake db:migrate 迁移数据

3.创建model 添加关联
$ rails generate model Comment commenter:string body:text article:references

4.在文件中 config/routes.rb 添加一个rest 动作
Rails.application.routes.draw do
resources :articles
end

$ bin/rake routes

5.进入控制台
rails c

原文地址:https://www.cnblogs.com/keno32/p/5189359.html