0

在以下情况下,我在获取嵌套表单的参数时遇到问题:

我有这 3 个嵌套模型

会议:

class Meeting < ActiveRecord::Base
 has_many :participants
end

参与者:

class Participant < ActiveRecord::Base
 belongs_to :meeting
 has_many :connections
end

和连接:

class Connection < ActiveRecord::Base
 belongs_to :participant, :foreign_key => 'connected_participant_id'
end

这些路线

resources :meetings do
    resources :participants
end

resources :participants do
    resources :connections
end

我成功地制作了一个表格来创建参与者并将他们直接添加到会议中,如下所示:

视图 > 会议/节目中

= link_to 'Add current user to meeting', new_meeting_participant_url(@meeting)

视图 > 参与者/新

= form_for [@meeting, @participant] do |p|
    *form details*

创建时我成功接收参数 [:meeting_id],但是在使用以下配置在参与者之间创建连接时做同样的事情时,我没有得到我需要的参数

同一视图中 > 会议/节目

- @meeting.participants.each do |participant|
    = link_to new_participant_connection_url(participant)

再次表单视图 > 连接/新建

= form_for [@participant, @connection] do |c|

通过调试,我注意到未设置所需的参数 [:participant_id]。

谁能帮我解决我的问题?我真的被困在这里了。

4

1 回答 1

2

也许你应该看看ActiveRecord::NestedAttributes::ClassMethods accept_nested_attributes_for

于 2010-12-29T22:53:29.677 回答