Thanks for all your help above
Coming back to the original query (now that I’m back at work to try it),
when I create a “component instance” i get the following in the logs:
Processing FolderController#new (for 127.0.0.1 at 2006-11-21 10:23:29)
[POST]
Session ID: e3154e167b8382c5050468c261bd0ead
Parameters: {“commit”=>“Add”, “folder”=>{“name”=>“cool folder”},
“action”=>“new”, “controller”=>“admin/construction/folder”,
“parent_id”=>“12”}
e[4;36;1mFolder Columns (0.016000)e[0m e[0;1mSHOW FIELDS FROM
folderse[0m
e[4;35;1mSQL (0.000000)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.046000)e[0m e[0;1mINSERT INTO folders (name
)
VALUES(‘cool folder’)e[0m
e[4;35;1mSQL (0.094000)e[0m e[0mCOMMITe[0m
e[4;36;1mComponentInstance Columns (0.016000)e[0m e[0;1mSHOW FIELDS
FROM component_instancese[0m
e[4;35;1mComponent Load (0.015000)e[0m e[0mSELECT * FROM components
WHERE (technical_name = ‘folder’) LIMIT 1e[0m
e[4;36;1mComponent Columns (0.000000)e[0m e[0;1mSHOW FIELDS FROM
componentse[0m
e[4;35;1mSQL (0.000000)e[0m e[0mBEGINe[0m
e[4;36;1mComponentInstance Load (0.000000)e[0m e[0;1mSELECT * FROM
component_instances WHERE (parent_id) ORDER BY position DESC LIMIT 1e[0m
e[4;35;1mSQL (0.032000)e[0m e[0mINSERT INTO component_instances
(deleted_root_item
, instance_type
, deleted_on
, enabled
,
instance_id
, component_id
, parent_id
, position
) VALUES(NULL,
‘Folder’, NULL, 1, 4, 2, 12, 5)e[0m
ferret_create/update: ComponentInstance : 20
creating doc for class: ComponentInstance, id: 20
e[4;36;1mSQL (0.031000)e[0m e[0;1mCOMMITe[0m
Redirected to
http://localhost:3001/admin/construction/construction_zone/12
Completed in 1.01600 (0 reqs/sec) | DB: 0.25000 (24%) | 302 Found
[http://localhost/admin/construction/folder/12/new]
The current model code is:
class ComponentInstance < ActiveRecord::Base
has_many :permissions
has_many :groups, :through => :permissions
belongs_to :component #will be in different database ??
acts_as_tree :order => ‘position’
acts_as_list :scope => ‘parent_id’
belongs_to :instance, :polymorphic => true
acts_as_ferret(
:fields => :instance_name
)
def instance_name
instance.name
end
– And here is the controller method to make a new folder
(component_instance)
def new
if request.post?
@folder = Folder.new(params[:folder])
success = @folder.save
component_instance = ComponentInstance.new
component_instance.enabled = 1; #ie True
component_instance.instance = @folder
component_instance.parent_id = params[:parent_id]
component_instance.component = Component.find(:first, :conditions
=>“technical_name = ‘folder’”)
if success && component_instance.save
flash[:notice] = 'A new folder was successfully added.'
redirect_to :controller => 'construction_zone', :parent_id =>
params[:parent_id]
else
@folder.destroy if success #Make sure the link and
component_instances tables are consistent
flash[:fail] = ‘There was an error when saving the folder’
end
else
@folder = Folder.new
end
end
Any ideas would be greatly appreciated.
Brendon