0

私は Ruby on Rails の初心者で、自分のプロジェクトを書くことによって、この難しい方法を学ぼうとしています。

テストに多くの問題が含まれており、他のテストでも問題を再利用できるシナリオがあります。だから私はこのようなモデルを作成しました。

  class Test < ActiveRecord::Base
    has_many :test_problems
    has_and_belongs_to_many :problems
    has_many :problems, :through => :test_problems

    belongs_to :user

    attr_accessible :name, :user_id, :reusable
  end

class Problem < ActiveRecord::Base
    belongs_to :user
    has_many :test_problems
    has_and_belongs_to_many :tests
    has_many :tests, :through => :test_problems

    attr_accessible :name, :statement, :input, :output, :user_id , :reusable
end

class TestProblem < ActiveRecord::Base
    belongs_to :test
    belongs_to :problem

    attr_accessible :problem_id, :test_id
end

これで、保存後にテストコントローラーの作成で関連付けを正しく追加できることをテストしました。

@test.problems << Problem.find( :last )

ユーザーが新しい問題を作成するときに、テストに多くの問題を追加する方法を探しています。これを処理するビューとコントローラーのコードを書くことができません。必要な JavaScript。最初に解決策が適切であり、次に部分的なエクストラを使用してこれを最適化する方法が素晴らしいでしょう.

-ヘマント

4

0 に答える 0