Ruby on rails 多对多关联的视图[Rails]

Ruby on rails 多对多关联的视图[Rails],ruby-on-rails,associations,Ruby On Rails,Associations,我是RubyonRails的新手,通过编写自己的项目,努力学习这一点 我有一个场景,其中一个测试包含许多问题,并且问题也可以在其他测试中重用。所以我创建了类似这样的模型 class Test < ActiveRecord::Base has_many :test_problems has_and_belongs_to_many :problems has_many :problems, :through => :test_problems bel

我是RubyonRails的新手,通过编写自己的项目,努力学习这一点

我有一个场景,其中一个测试包含许多问题,并且问题也可以在其他测试中重用。所以我创建了类似这样的模型

  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。首先一个解决方案是好的,然后如何继续优化这个使用部分额外将是伟大的


-Hemant

有且属于多个:测试有多个:测试,:通过=>:测试问题在我看来,相同的关系定义了两次。我可以删除它。我感兴趣的主要问题是如何编写视图