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) 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:
<http://rubyforge.org/pipermail/betternestedset-talk/attachments/20081103/f61b8d43/attachment.html>