activeadmin一对一关联不保存id

时间:2014-12-01 16:37:57

标签: ruby-on-rails activeadmin

为什么未保存关联的记录ID?

Diagram of database
Console error message

Activeadmin screenshot

教师迁移

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

1 个答案:

答案 0 :(得分:2)

我猜你在permit_params中忘了昏迷:

ActiveAdmin.register Teacher do
  permit_params{
    :id,
    :classroom_id,
    :name
  }
end