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