2014-12-01 93 views
0

爲什麼沒有保存關聯的記錄ID?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 
+0

請問您能否顯示您的視圖和控制器? – 2014-12-01 16:45:23

+0

由於activeadmin,沒有控制器或視圖。我正在使用生成的默認視圖。到目前爲止,app/admin/teacher.rb文件中只有許可參數。 – sasdev 2014-12-01 17:07:02

回答

2

我猜你忘記了昏迷在permit_params中:

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

我刪除了{}並添加了逗號,這是固定的問題。謝謝 – sasdev 2014-12-01 19:09:22