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”?
Use
generate migration add_flow_id_to_page flow_id:integerto generate the foreign key column.