From anja-email1 at web.de Mon Nov 3 11:13:30 2008 From: anja-email1 at web.de (Andrea Jahn) Date: Mon, 03 Nov 2008 17:13:30 +0100 Subject: [Betternestedset-talk] Problem with parent_id Message-ID: <1085635047@web.de> Hi, I tried to make a simple example with BetterNestedSet and have a problem with the parent_id. Migration: ------------ class CreateItems < ActiveRecord::Migration def self.up create_table :items do |t| # nested set t.integer :root_id t.integer :parent_id t.integer :lft, :null => false t.integer :rgt, :null => false t.string :name, :limit => 255, :null => false, :default => "" t.string :description, :limit => 512, :null => false, :default => "" t.integer :hw_model_id, :null => false t.boolean :deleted, :null => false, :default => false t.timestamps end end def self.down drop_table :items end end In the view for entering a new item there's a selection box for selecting the parent node (value = id). Request parameters posted to the action create: -------------------------------------------------------------- {"commit"=>"Create", "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "item"=>{"name"=>"hdhdfhdfhfh", "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", "workaround_id"=>"11"}} Controller: ------------- def create @item = Item.new(params[:item]) p @item.parent_id <-------------------------- nil ????? p @item.workaround_id @parent = Item.find(@item.workaround_id) if @parent p "parent gefunden" @item.root_id = @parent.root_id end if @item.save if not @parent p "parent nicht gefunden" # this item has no parent, so it is the root of a new tree @item.update_attribute("root_id", @item.id) else @item.move_to_child_of @parent end flash[:notice] = 'Item was successfully created.' format.html { redirect_to(@item) } <------------------------ error: too few arguments ???? format.xml { render :xml => @item, :status => :created, :location => @item } else format.html { render :action => "new" } format.xml { render :xml => @item.errors, :status => :unprocessable_entity } end end Logfile: -------- Parameters: {"commit"=>"Create", "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "action"=>"create", "controller"=>"items", "item"=>{"name"=>"hdhdfhdfhfh", "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", "workaround_id"=>"11"}} Item Columns (0.031000) SHOW FIELDS FROM `items` WARNING: Can't mass-assign these protected attributes: parent_id !!!!!!!!!!!!!!!!!!!!!!!! ------------------------- I have installed the plugin svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset and I'm using Rails 2.1.0 Thanks in advance Andrea Psssst! Schon vom neuen WEB.DE MultiMessenger geh?rt? Der kann`s mit allen: *http://www.produkte.web.de/messenger/?did=3123* [http://www.produkte.web.de/messenger/?did=3123] -------------- next part -------------- An HTML attachment was scrubbed... URL: From anja-email1 at web.de Mon Nov 3 11:49:30 2008 From: anja-email1 at web.de (Andrea Jahn) Date: Mon, 03 Nov 2008 17:49:30 +0100 Subject: [Betternestedset-talk] Problem with parent_id Message-ID: <1085717384@web.de> Hi, I found out that the parent_id is a protected attribute. So I cannot write this attribute without using the API of BetterNestedSet. There might be a good reason for that. Because of that it is not possible to use a field in the form to select the parent_id (f.collection_select) of the model resource. I will find another way for the user to select the item, which should be the parent for the new item. Andrea Hi, I tried to make a simple example with BetterNestedSet and have a problem with the parent_id. Migration: ------------ class CreateItems < ActiveRecord::Migration def self.up create_table :items do |t| # nested set t.integer :root_id t.integer :parent_id t.integer :lft, :null => false t.integer :rgt, :null => false t.string :name, :limit => 255, :null => false, :default => "" t.string :description, :limit => 512, :null => false, :default => "" t.integer :hw_model_id, :null => false t.boolean :deleted, :null => false, :default => false t.timestamps end end def self.down drop_table :items end end In the view for entering a new item there's a selection box for selecting the parent node (value = id). Request parameters posted to the action create: -------------------------------------------------------------- {"commit"=>"Create", "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "item"=>{"name"=>"hdhdfhdfhfh", "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", "workaround_id"=>"11"}} Controller: ------------- def create @item = Item.new(params[:item]) p @item.parent_id <-------------------------- nil ????? p @item.workaround_id @parent = Item.find(@item.workaround_id) if @parent p "parent gefunden" @item.root_id = @parent.root_id end if @item.save if not @parent p "parent nicht gefunden" # this item has no parent, so it is the root of a new tree @item.update_attribute("root_id", @item.id) else @item.move_to_child_of @parent end flash[:notice] = 'Item was successfully created.' format.html { redirect_to(@item) } <------------------------ error: too few arguments ???? format.xml { render :xml => @item, :status => :created, :location => @item } else format.html { render :action => "new" } format.xml { render :xml => @item.errors, :status => :unprocessable_entity } end end Logfile: -------- Parameters: {"commit"=>"Create", "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "action"=>"create", "controller"=>"items", "item"=>{"name"=>"hdhdfhdfhfh", "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", "workaround_id"=>"11"}} [4;35;1mItem Columns (0.031000)[0m [0mSHOW FIELDS FROM `items`[0m WARNING: Can't mass-assign these protected attributes: parent_id !!!!!!!!!!!!!!!!!!!!!!!! ------------------------- I have installed the plugin svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset and I'm using Rails 2.1.0 Thanks in advance Andrea Schon geh?rt? Bei WEB.DE gibt' s viele kostenlose Spiele: *http://games.entertainment.web.de/de/entertainment/games/free/index.html* [http://games.entertainment.web.de/de/entertainment/games/free/index.html] -------------- next part -------------- An HTML attachment was scrubbed... URL: From beholdthepanda at gmail.com Mon Nov 3 19:31:36 2008 From: beholdthepanda at gmail.com (Stephen Schor) Date: Mon, 3 Nov 2008 19:31:36 -0500 Subject: [Betternestedset-talk] Problem with parent_id In-Reply-To: <1085717384@web.de> References: <1085717384@web.de> Message-ID: <45e5e9bc0811031631q64fb063bl1177fb29fc22524b@mail.gmail.com> Heyo Andrea... I save the node - then end up calling .move_to_child_of(parent_id). My models have their own methods that end up calling a few of the BNS methods. This is copied and pasted directly from the plugin's README in acts_as_nested_set: # adds a new item at the "end" of the tree, i.e. with child.left = max(tree.right) + 1 child = MyClass.create(:name => "child1") # now move the item to its desired location child.move_to_child_of my_item You can use: * move_to_child_of * move_to_right_of * move_to_left_of and pass them an id or an object. -Stephen On Mon, Nov 3, 2008 at 11:49 AM, Andrea Jahn wrote: > > Hi, > > I found out that the parent_id is a protected attribute. So I cannot write > this attribute > without using the API of BetterNestedSet. There might be a good reason for > that. > > Because of that it is not possible to use a field in the form to select the > parent_id (f.collection_select) > of the model resource. I will find another way for the user to select the > item, which should be the parent > for the new item. > > Andrea > > > > Hi, > > I tried to make a simple example with BetterNestedSet and have a problem > with the parent_id. > > Migration: > ------------ > class CreateItems < ActiveRecord ::Migration > def self.up > create_table :items do |t| > # nested set > t.integer :root_id > t.integer :parent_id > t.integer :lft, :null => false > t.integer :rgt, :null => false > > t.string :name, :limit => 255, :null => false, > :default => "" > t.string : description, :limit => 512, :null => false, > :default => "" > t.integer :hw_model_id, :null => false > t.boolean :deleted, :null => > false, :default => false > > t.timestamps > end > end > > def self.down > drop_table :items > end > end > > In the view for entering a new item there's a selection box for selecting > the parent node (value = id). > > Request parameters posted to the action create: > -------------------------------------------------------------- > {"commit"=>"Create", > "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", > "item"=>{"name"=>"hdhdfhdfhfh", > "hw_model_id"=>"996332897", > "description"=>"", > "parent_id"=>"11", > "workaround_id"=>"11"}} > > Controller: > ------------- > def create > @item = Item.new(params[:item]) > p @item.parent_id <-------------------------- nil ????? > p @item.workaround_id > @parent = Item.find(@item.workaround_id) > if @parent > p "parent gefunden" > @item.root_id = @parent.root_id > end > if @item.save > if not @parent > p "parent nicht gefunden" > # this item has no parent, so it is the root of a new tree > @item.update_attribute("root_id", @item.id) > else > @item.move_to_child_of @parent > end > > flash[:notice] = 'Item was successfully created.' > format.html { redirect_to(@item) } > <------------------------ error: too few arguments ???? > format.xml { render :xml => @item, :status => :created, :location => > @item } > else > format.html { render :action => "new" } > format.xml { render :xml => @item.errors, :status => > :unprocessable_entity } > end > end > > Logfile: > -------- > Parameters: {"commit"=>"Create", > "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "acti > on"=>"create", "controller"=>"items", "item"=>{"name"=>"hdhdfhdfhfh", > "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", > "workaround_id"=>"11"}} > > [4;35;1mItem Columns (0.031000)[0m [0mSHOW FIELDS FROM `items`[0m > > WARNING: Can't mass-assign these protected attributes: parent_id > !!!!!!!!!!!!!!!!!!!!!!!! > ------------------------- > > I have installed the plugin > svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset > and I'm using Rails 2.1.0 > > Thanks in advance > Andrea > > > > Schon geh?rt? Bei WEB.DE gibt' s viele kostenlose Spiele: > *http://games.entertainment.web.de/de/entertainment/games/free/index.html* > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anja-email1 at web.de Thu Nov 6 12:31:32 2008 From: anja-email1 at web.de (Andrea Jahn) Date: Thu, 06 Nov 2008 18:31:32 +0100 Subject: [Betternestedset-talk] Problem with parent_id Message-ID: <1091988774@web.de> Hi, in the view I have now: <%= select_tag("parent_id", "" + options_from_collection_for_select(@items, :id, :name)) %> instead of: <%= f.collection_select :parent_id, @items, :id, :name, :prompt => "Please select" %> Then I can find the parent in the controller: @parent = Item.find(params[:parent_id]) and add the parent (id) to the child with the help of one of the BNS methods (and update lft and rgt): @item.move_to_child_of @parent Thanks Andrea *Von:* "Stephen Schor" *Gesendet:* 04.11.08 01:33:35 *An:* betternestedset-talk at rubyforge.org *Betreff:* Re: [Betternestedset-talk] Problem with parent_id Heyo Andrea... I save the node - then end up calling .move_to_child_of(parent_id). My models have their own methods that end up calling a few of the BNS methods. This is copied and pasted directly from the plugin's README in acts_as_nested_set: # adds a new item at the "end" of the tree, i.e. with child.left = max(tree.right) + 1 child = MyClass.create(:name => "child1") # now move the item to its desired location child.move_to_child_of my_item You can use: * move_to_child_of * move_to_right_of * move_to_left_of and pass them an id or an object. -Stephen On Mon, Nov 3, 2008 at 11:49 AM, Andrea Jahn wrote: Hi, I found out that the parent_id is a protected attribute. So I cannot write this attribute without using the API of BetterNestedSet. There might be a good reason for that. Because of that it is not possible to use a field in the form to select the parent_id (f.collection_select) of the model resource. I will find another way for the user to select the item, which should be the parent for the new item. Andrea Hi, I tried to make a simple example with BetterNestedSet and have a problem with the parent_id. Migration: ------------ class CreateItems < ActiveRecord ::Migration def self.up create_table :items do |t| # nested set t.integer :root_id t.integer :parent_id t.integer :lft, :null => false t.integer :rgt, :null => false t.string :name, :limit => 255, :null => false, :default => "" t.string : description, :limit => 512, :null => false, :default => "" t.integer :hw_model_id, :null => false t.boolean :deleted, :null => false, :default => false t.timestamps end end def self.down drop_table :items end end In the view for entering a new item there's a selection box for selecting the parent node (value = id). Request parameters posted to the action create: -------------------------------------------------------------- {"commit"=>"Create", "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "item"=>{"name"=>"hdhdfhdfhfh", "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", "workaround_id"=>"11"}} Controller: ------------- def create @item = Item.new(params[:item]) p @item.parent_id <-------------------------- nil ????? p @item.workaround_id @parent = Item.find(@item.workaround_id) if @parent p "parent gefunden" @item.root_id = @parent.root_id end if @item.save if not @parent p "parent nicht gefunden" # this item has no parent, so it is the root of a new tree @item.update_attribute("root_id", @item.id [http://item.id/]) else @item.move_to_child_of @parent end flash[:notice] = 'Item was successfully created.' format.html { redirect_to(@item) } <------------------------ error: too few arguments ???? format.xml { render :xml => @item, :status => :created, :location => @item } else format.html { render :action => "new" } format.xml { render :xml => @item.errors, :status => :unprocessable_entity } end end Logfile: -------- Parameters: {"commit"=>"Create", "authenticity_token"=>"6815a1cad4c491f5a243263eafdd4275ba86697b", "acti on"=>"create", "controller"=>"items", "item"=>{"name"=>"hdhdfhdfhfh", "hw_model_id"=>"996332897", "description"=>"", "parent_id"=>"11", "workaround_id"=>"11"}} [4;35;1mItem Columns (0.031000)[0m [0mSHOW FIELDS FROM `items`[0m WARNING: Can't mass-assign these protected attributes: parent_id !!!!!!!!!!!!!!!!!!!!!!!! ------------------------- I have installed the plugin svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset [http://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset] and I'm using Rails 2.1.0 Thanks in advance Andrea Schon geh?rt? Bei WEB.DE [http://web.de/] gibt' s viele kostenlose Spiele: *http://games.entertainment.web.de/de/entertainment/games/free/index.html* [http://games.entertainment.web.de/de/entertai%0A+nment/games/free/index.html] _______________________________________________ Betternestedset-talk mailing list Betternestedset-talk at rubyforge.org [mailto:Betternestedset-talk at rubyforge.org] http://rubyforge.org/mailman/listinfo/betternestedset-talk [http://rubyforge.org/mailman/listinfo/betternestedset-talk] _______________________________________________Betternestedset-talk mailing listBetternestedset-talk at rubyforge.orghttp://rubyforge.org/mailman/listinfo/betternestedset-talk "Run, Fatboy, Run" sowie "Rails & Ties" kostenlos anschauen! Blockbuster-Gutscheine sichern unter *http://www.blockbuster.web.de* [http://www.blockbuster.web.de] -------------- next part -------------- An HTML attachment was scrubbed... URL: