ruby on rails - awesome_nested_set duplicating children in a select -
i having problem awesome_nested_set duplicating children in select (as title says)
i have following data in table (phpmyadmin put quotes around 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 need more info can post it, thought relevant problem.
edit:
i getting 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 comes out fine.
and did in 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
i figured out, using:
# controller @destination_groups = destinationgroup.all then:
# view = f.select :destination_group_id, options_for_select(nested_set_options(@destination_groups) {|i| "#{'-' * i.level} #{i.name}" } ) i changed to:
# view = f.select :destination_group_id, options_for_select(nested_set_options(destinationgroup) {|i| "#{'-' * i.level} #{i.name}" } ) i guessing duplicating destinationgroup.all, anyways fixed incase runs again.
Comments
Post a Comment