如何从各种两个表创建具有多个字段关系的脚手架

时间:2016-07-30 08:57:47

标签: ruby-on-rails scaffolding

我想用下面的引用为表创建一个脚手架。此处transport_supervisor_idmanager_idloading_supervisor_id这些内容属于用户表引用

  load_type_id (belongs_to load_type)
  load_pick_from_date (date)
  load_pick_to_date (date)
  price (decimal presision 9,2)
  transport_supervisor_id (belongs_to user)
  manager_id (belongs_to user)
  loading_supervisor_id (belongs_to user)
  company_id (belongs_to company)

我怎样才能这样创作?我想只创建这个rails g scaffolding命令。

1 个答案:

答案 0 :(得分:0)

例如;

rails generate scaffold manager name:string

rails g scaffold supervisor name:string manager:belongs_to

输出;

create_table "supervisors", force: :cascade do |t|
   t.string   "name"
   t.integer  "manager_id"
   t.datetime "created_at", null: false
   t.datetime "updated_at", null: false
end

create_table "managers", force: :cascade do |t|
   t.string   "name"
   t.datetime "created_at", null: false
   t.datetime "updated_at", null: false
end

我希望,在这种情况下,它会帮助你。