为什么未保存关联的记录ID?
Diagram of database
Console error message
教师迁移
class CreateTeachers < ActiveRecord::Migration
def change
create_table :teachers do |t|
t.string :name
t.belongs_to :classroom
t.timestamps
end
end
end
课堂迁移
class CreateClassrooms < ActiveRecord::Migration
def change
create_table :classrooms do |t|
t.string :name
t.timestamps
end
end
end
模型/ teacher.rb
class Teacher < ActiveRecord::Base
belongs_to :classroom
end
模型/ classroom.rb
class Classroom < ActiveRecord::Base
has_one :teacher
end
应用/管理/ teacher.rb
ActiveAdmin.register Teacher do
permit_params{
:id
:classroom_id
:name
}
end
答案 0 :(得分:2)
我猜你在permit_params中忘了昏迷:
ActiveAdmin.register Teacher do
permit_params{
:id,
:classroom_id,
:name
}
end