resources :flows do
resources :fmodules
end
fmodules控制器中的新方法:
# /flows/1/fmodules/new
def new
@flow = Flow.find(params[:flow_id])
@fmodule = @flow.fmodules.build
end
模型:
class Flow < ApplicationRecord
has_many :fmodules, dependent: :destroy
validates :code, presence: true, length: { maximum: 5 }
validates :name, presence: true
end
class Fmodule < ApplicationRecord
belongs_to :flow
end
/flows/1/fmodules/new
ruby说
unknown attribute 'flow_id' for Fmodule.
我不知道怎么了
此外,这是Fmodel的迁移
class CreateFmodules < ActiveRecord::Migration[5.1]
def change
create_table :fmodules do |t|
t.string :code
t.string :name
t.string :f_code
t.timestamps
end
add_foreign_key :fmodules, :flows, column: :f_code
end
end