0

我正在使用一个允许用户将新内容添加到装运箱的产品。例如:

用户正在设置一个货件,每个货件可以包含多个箱子,每个箱子可以包含多个内容。

所以我link_to_remote像这样连接:

在我的装运箱部分:

<div class="shipping_box" id="shipping_box">
    #some code
    <%= link_to_remote "Add box conents", :url => {:action=> 'add_box_contents'} %>
</div>

add_box_contents.rjs

page.insert_html :bottom, "shipping_box", :partial => 'box_content', :object => BoxContent.new

并且在_box_content.erb

<div class="box_contents" id="box_contents">
   box contents partial rendered
</div>

对于我的第一个运输箱,一切正常,但是当动态添加第二个运输箱时,_box_content.erb部分总是呈现在<div>第一个箱中。当然这是因为 id 被指定为shipping_box,并且所有盒子共享这个 id。那么我的问题是,如何在 div 中为正确的包含框呈现新的框内容,而不仅仅是删除第一个框?

此屏幕截图显示了第一个框,其中包含 2 个动态添加的内容行(下拉菜单)。我希望第二个框的“添加订单行项目”行向我的第二个框的内容添加一个下拉列表。 替代文字 http://img12.imageshack.us/img12/6274/screenshot20100622at114.png

4

2 回答 2

0

您的 rjs 可能应该使用replace_html()而不是insert_html()

page.replace_html "shipping_box", :partial => 'box_content', :object => BoxContent.new
于 2010-06-23T02:47:47.337 回答
0

您实际上想要渲染部分“select_order_line”,以便仅将相应的部分添加到运输箱中。因此,只需将其分解,然后您就可以编写:

page.insert_html :bottom, "box_content", :partial => 'select_order_line'
于 2010-07-19T19:11:11.363 回答