Ruby on rails Rails 3.1构建关联

Ruby on rails Rails 3.1构建关联,ruby-on-rails,controller,associations,ruby-on-rails-3.1,Ruby On Rails,Controller,Associations,Ruby On Rails 3.1,所以我有一个流模型和一个页面模型 每个流都有许多页面,每个页面都属于一个流 流动模型 class Flow < ActiveRecord::Base has_many :pages, :dependent => :destroy accepts_nested_attributes_for :pages, :reject_if => lambda { |p| p[:path].blank?}, :allow_destroy => true end 但我一直收到错误:“未知

所以我有一个流模型和一个页面模型

每个流都有许多页面,每个页面都属于一个流

流动模型

class Flow < ActiveRecord::Base
has_many :pages, :dependent => :destroy
accepts_nested_attributes_for :pages, :reject_if => lambda { |p| p[:path].blank?}, :allow_destroy => true
end

但我一直收到错误:“未知属性:flow\u id”?

使用
生成迁移将流id添加到页面流id:integer
生成外键列。

使用
生成迁移将流id添加到页面流id:integer
生成外键列。

您的
页面
模型确实有
流id
字段,对吗?(您已经运行了迁移以确保数据库中有吗?)为Flow和Page Tables显示文件db/schema.rb您的
Page
模型确实有
Flow\u id
字段,对吗?(您已经运行了迁移以确保数据库中有它吗?)显示流表和页表的db/schema.rb文件
class Page < ActiveRecord::Base
  belongs_to :flow
end
def new
    @flow = Flow.new
    3.times do
      page = @flow.pages.build
    end
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @flow }
    end
  end