Awesome_nested_set 在选择中复制子项
我在选择中遇到 Awesome_nested_set 复制子项的问题(如标题所示)
我在表中有以下数据(phpmyadmin 在字段周围加引号):
id name parent_id lft rgt created_at updated_at
"12" "BNW" NULL "1" "8" "2010-12-01 22:23:36" "2010-12-01 22:23:36"
"13" "NYSSA" "12" "2" "3" "2010-12-01 22:23:48" "2010-12-01 22:25:12"
"14" "BOARDMAN" "12" "4" "5" "2010-12-01 22:25:28" "2010-12-01 22:25:28"
"15" "QUINCY" "12" "6" "7" "2010-12-01 22:25:37" "2010-12-01 22:25:37"
"16" "WCC" NULL "9" "16" "2010-12-02 18:08:00" "2010-12-02 18:08:00"
"17" "CALIFORNIA" "16" "10" "11" "2010-12-02 18:08:08" "2010-12-02 18:08:08"
"18" "NORTH POWDER" "16" "12" "13" "2010-12-02 18:08:16" "2010-12-02 18:08:16"
"19" "ELLENSBURG" "16" "14" "15" "2010-12-02 18:08:25" "2010-12-02 18:08:25"
模型:
class DestinationGroup < ActiveRecord::Base
acts_as_audited
has_one :purchase
acts_as_nested_set
end
控制器:
class PurchasesController < ApplicationController
def new
@destination_groups = DestinationGroup.all
...
end
...
视图:
= f.select :destination_group_id, options_for_select(nested_set_options(@destination_groups) {|i| "#{'-' * i.level} #{i.name}" } )
如果您需要更多信息,我可以发布它,但我认为这就是与问题真正相关的全部内容。
编辑:
我得到这个html:
<select id="purchase_destination_group_id" name="purchase[destination_group_id]">
<option value="12"> BNW</option>
<option value="13">- NYSSA</option>
<option value="14">- BOARDMAN</option>
<option value="15">- QUINCY</option>
<option value="13">- NYSSA</option>
<option value="14">- BOARDMAN</option>
<option value="15">- QUINCY</option>
<option value="16"> WCC</option>
<option value="17">- CALIFORNIA</option>
<option value="18">- NORTH POWDER</option>
<option value="19">- ELLENSBURG</option>
<option value="17">- CALIFORNIA</option>
<option value="18">- NORTH POWDER</option>
<option value="19">- ELLENSBURG</option>
</select>
编辑2
这变得更奇怪:
DestinationGroup.all.collect{|i| "#{'-' * i.level} #{i.name}" }
=> [" BNW", "- NYSSA", "- BOARDMAN", "- QUINCY", " WCC", "- CALIFORNIA", "- NORTH POWDER", "- ELLENSBURG"]
这显然效果很好。
我在视图中这样做了:
= "<!-- #{@destination_groups.inspect} -->"
<!--
[
#<DestinationGroup id: 12, name: "BNW", parent_id: nil, lft: 1, rgt: 8, created_at: "2010-12-01 22:23:36", updated_at: "2010-12-01 22:23:36">,
#<DestinationGroup id: 13, name: "NYSSA", parent_id: 12, lft: 2, rgt: 3, created_at: "2010-12-01 22:23:48", updated_at: "2010-12-01 22:25:12">,
#<DestinationGroup id: 14, name: "BOARDMAN", parent_id: 12, lft: 4, rgt: 5, created_at: "2010-12-01 22:25:28", updated_at: "2010-12-01 22:25:28">,
#<DestinationGroup id: 15, name: "QUINCY", parent_id: 12, lft: 6, rgt: 7, created_at: "2010-12-01 22:25:37", updated_at: "2010-12-01 22:25:37">,
#<DestinationGroup id: 16, name: "WCC", parent_id: nil, lft: 9, rgt: 16, created_at: "2010-12-02 18:08:00", updated_at: "2010-12-02 18:08:00">,
#<DestinationGroup id: 17, name: "CALIFORNIA", parent_id: 16, lft: 10, rgt: 11, created_at: "2010-12-02 18:08:08", updated_at: "2010-12-02 18:08:08">,
#<DestinationGroup id: 18, name: "NORTH POWDER", parent_id: 16, lft: 12, rgt: 13, created_at: "2010-12-02 18:08:16", updated_at: "2010-12-02 18:08:16">,
#<DestinationGroup id: 19, name: "ELLENSBURG", parent_id: 16, lft: 14, rgt: 15, created_at: "2010-12-02 18:08:25", updated_at: "2010-12-02 18:08:25">
]
-->
谢谢
I am having a problem with awesome_nested_set duplicating children in a select (as the title says)
I have the following data in the table (phpmyadmin put quotes around the fields):
id name parent_id lft rgt created_at updated_at
"12" "BNW" NULL "1" "8" "2010-12-01 22:23:36" "2010-12-01 22:23:36"
"13" "NYSSA" "12" "2" "3" "2010-12-01 22:23:48" "2010-12-01 22:25:12"
"14" "BOARDMAN" "12" "4" "5" "2010-12-01 22:25:28" "2010-12-01 22:25:28"
"15" "QUINCY" "12" "6" "7" "2010-12-01 22:25:37" "2010-12-01 22:25:37"
"16" "WCC" NULL "9" "16" "2010-12-02 18:08:00" "2010-12-02 18:08:00"
"17" "CALIFORNIA" "16" "10" "11" "2010-12-02 18:08:08" "2010-12-02 18:08:08"
"18" "NORTH POWDER" "16" "12" "13" "2010-12-02 18:08:16" "2010-12-02 18:08:16"
"19" "ELLENSBURG" "16" "14" "15" "2010-12-02 18:08:25" "2010-12-02 18:08:25"
Model:
class DestinationGroup < ActiveRecord::Base
acts_as_audited
has_one :purchase
acts_as_nested_set
end
Controller:
class PurchasesController < ApplicationController
def new
@destination_groups = DestinationGroup.all
...
end
...
View:
= f.select :destination_group_id, options_for_select(nested_set_options(@destination_groups) {|i| "#{'-' * i.level} #{i.name}" } )
If you need more info I can post it, but I thought this was all that was really relevant to the problem.
EDIT:
I am getting this html:
<select id="purchase_destination_group_id" name="purchase[destination_group_id]">
<option value="12"> BNW</option>
<option value="13">- NYSSA</option>
<option value="14">- BOARDMAN</option>
<option value="15">- QUINCY</option>
<option value="13">- NYSSA</option>
<option value="14">- BOARDMAN</option>
<option value="15">- QUINCY</option>
<option value="16"> WCC</option>
<option value="17">- CALIFORNIA</option>
<option value="18">- NORTH POWDER</option>
<option value="19">- ELLENSBURG</option>
<option value="17">- CALIFORNIA</option>
<option value="18">- NORTH POWDER</option>
<option value="19">- ELLENSBURG</option>
</select>
Edit 2
This gets weirder:
DestinationGroup.all.collect{|i| "#{'-' * i.level} #{i.name}" }
=> [" BNW", "- NYSSA", "- BOARDMAN", "- QUINCY", " WCC", "- CALIFORNIA", "- NORTH POWDER", "- ELLENSBURG"]
this obviously comes out just fine.
and I did this in the view:
= "<!-- #{@destination_groups.inspect} -->"
<!--
[
#<DestinationGroup id: 12, name: "BNW", parent_id: nil, lft: 1, rgt: 8, created_at: "2010-12-01 22:23:36", updated_at: "2010-12-01 22:23:36">,
#<DestinationGroup id: 13, name: "NYSSA", parent_id: 12, lft: 2, rgt: 3, created_at: "2010-12-01 22:23:48", updated_at: "2010-12-01 22:25:12">,
#<DestinationGroup id: 14, name: "BOARDMAN", parent_id: 12, lft: 4, rgt: 5, created_at: "2010-12-01 22:25:28", updated_at: "2010-12-01 22:25:28">,
#<DestinationGroup id: 15, name: "QUINCY", parent_id: 12, lft: 6, rgt: 7, created_at: "2010-12-01 22:25:37", updated_at: "2010-12-01 22:25:37">,
#<DestinationGroup id: 16, name: "WCC", parent_id: nil, lft: 9, rgt: 16, created_at: "2010-12-02 18:08:00", updated_at: "2010-12-02 18:08:00">,
#<DestinationGroup id: 17, name: "CALIFORNIA", parent_id: 16, lft: 10, rgt: 11, created_at: "2010-12-02 18:08:08", updated_at: "2010-12-02 18:08:08">,
#<DestinationGroup id: 18, name: "NORTH POWDER", parent_id: 16, lft: 12, rgt: 13, created_at: "2010-12-02 18:08:16", updated_at: "2010-12-02 18:08:16">,
#<DestinationGroup id: 19, name: "ELLENSBURG", parent_id: 16, lft: 14, rgt: 15, created_at: "2010-12-02 18:08:25", updated_at: "2010-12-02 18:08:25">
]
-->
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了,我正在使用:
then:
我将其更改为:
我猜它是从 DestinationGroup.all 复制的,无论如何它是固定的,以防有人再次遇到这个问题。
I figured it out, I was using:
then:
I changed it to:
I am guessing it was duplicating it from the DestinationGroup.all, anyways its fixed incase anyone runs into this again.