2011-06-29 7 views
0

これは私が達成しようとしているものです。私は学生が登録するコースを持っています。そのクラスの上級生を追跡したいと思います。私はcourse_resultsという別のモデルを設定しました。HABTMアソシエーションのフォーム作成

class CourseAdvanceType < ActiveRecord::Base 
    belongs_to :course 
    has_and_belongs_to_many :students 
end 

####### 
class Students < ActiveRecord::Base 
    has_many :courses 
    has_and_belongs_to_many :course_advance_types 
end 

####### 
class Courses < ActiveRecord::Base 
    has_one :course_advance_type 
    has_many :students 
end 

理想的には私は私がその下に生徒を追加することができます(アスレチック学術、)事前の種類の選択を可能にする小さなフォームをしたいです。各生徒は、HABTM関連のために作成されたcourse_advance_types_studentsテーブルに記録されます。このような

何か:

<form> 
    <select> 
    <option>academic</option> 
    <option>athletic</option> 
    </select> 
    <div id="students"> 
    <div>Student ID: <input type="text" /></div> 
    <div>Student ID: <input type="text" /></div> 
    <!-- This link would dynamically add another name field --> 
    <div><a href="[code]">Add Student</a></div> 
    </div> 
    <input type="submit> 
</form> 

これを実現する最良の方法は何ですか?私はaccepts_nested_attributes_forの使用について考えましたが、生徒の属性を設定したくないために動作しているかどうかわかりません。student_advance_type_idをcourse_advance_types_studentsテーブルに保存して、進級タイプのリストと生徒のリストを持って進学しているコース。

何かを明確にしたり、私のアプローチを再考する必要がある場合は、教えてください。

ありがとうございます。

答えて

関連する問題