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 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
但我不断收到错误:“未知属性:flow_id”?
So I have a flow model and a page model
Each flow has_many pages and each page belongs_to a flow
Flow model
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
Page model
class Page < ActiveRecord::Base
belongs_to :flow
end
Then in the new flow action I have this
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
but I keep getting the error: "unknown attribute: flow_id"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
generate migration add_flow_id_to_page flow_id:integer
生成外键列。Use
generate migration add_flow_id_to_page flow_id:integer
to generate the foreign key column.