2016-05-16 18 views
0

こんにちは私はモデルを作成する必要があります。モデル内の1つの列を他のモデルに関連付ける

class CreateLecturers < ActiveRecord::Migration 
    def change 
    create_table :lecturers do |t| 
     t.string :firstname 
     t.string :lastname 
     t.string :position 
     t.string :email 

     t.timestamps null: false 
    end 
    end 
end 

ここは私の2番目のモデルです。

class CreateCurriculums < ActiveRecord::Migration 
    def change 
    create_table :curriculums do |t| 
     t.string :title 
     t.integer :hours 
     t.integer :year 
     t.text :description 

     t.timestamps null: false 
    end 
    end 
end 

カリキュラムを講師に移行します。しかし、IDなしで、タイトルは どのようにすることができますか?

だから、私はrails-adminを使います。私はいくつかのカリキュラムを追加するときに私はドロップダウン講師で選びたいと思うし、講師をいくつか追加すると、モデル間のカリキュラムを選択したい。

答えて

0

何があっても、2つのモデルを関連付ける必要があります。また、テーブルlecturescurriculum_idを追加することを忘れないでください。

curriculum.rb

has_many :lectures 

lecture.rb

belongs_to :curriculum 

移行追加するには

rails g migration add_curriculum_id_to_lectures curriculum_id:integer

関連する問題