I have a class that uses acts_as_nested_set.
class GreenRoom < ActiveRecord::Base
acts_as_nested_set
has_many :children, :foreign_key => :parent_id, :class_name =>
'GreenRoom'
belongs_to :parent, :foreign_key => :parent_id, :class_name =>
'GreenRoom'
"other fields"
end
The controller has
class GreenRoomController < ApplicationController
active_scaffold :green_room do |config|
"other configs"
config.columns[:parent].ui_type = :select
config.nested.add_link("Next Level", [:children])
end
def conditions_for_collection
return ['parent_id is NULL'] if !params.has_key?(:nested)
end
end
this works in as expected in development but does not work in
production. In production, when I click the nested link I get a
nested list that has one record and that record is the record I have
just clicked.
The message in production log is as follows
Processing GreenRoomController#nested (for 127.0.0.1 at 2007-11-07
13:21:17) [GET]
Session ID: fce68e1a1b978fa6fdc15753b5f3e0c0
Parameters: {"associations"=>"children", "action"=>"nested",
"_method"=>"get", "adapter"=>"_list_inline_adapter", "id"=>"3",
"controller"=>"green_room"}
Start rendering component
({:controller=>"green_room", :params=>{:parent_model=>GreenRoom, :nested=>true, :eid=>"850dabbfba55f39ff85bba073a6f2fef", :parent_column=>"children"}, :action=>"table"}):
Processing GreenRoomController#table (for 127.0.0.1 at 2007-11-07
13:21:17) [GET]
Session ID: fce68e1a1b978fa6fdc15753b5f3e0c0
Parameters: {"eid"=>"850dabbfba55f39ff85bba073a6f2fef",
"parent_column"=>"children", "nested"=>true, "action"=>"table",
"id"=>nil, "controller"=>"green_room", "parent_model"=>GreenRoom}
Rendering ../../vendor/plugins/active_scaffold/frontends/default/views/
list
Completed in 0.18920 (5 reqs/sec) | Rendering: 0.06854 (36%) | DB:
0.00786 (4%) | 200 OK [http://onetruth/green_room/nested/3?
_method=get&associations=children&adapter=_list_inline_adapter]
End of component rendering
Rendering ../../vendor/plugins/active_scaffold/frontends/default/views/
_list_inline_adapter
Completed in 0.28523 (3 reqs/sec) | Rendering: 0.01492 (5%) | DB:
0.00000 (0%) | 200 OK [http://onetruth/green_room/nested/3?
_method=get&associations=children&adapter=_list_inline_adapter]
Any help is appriciated
White Wizzard
"long Query " childrens_green_rooms.parent_id = green_rooms.id WHERE
(green_rooms.id = '3') AND green_rooms.id IN ('3') This is in
production, and in the development it is
"long query" parents_green_rooms.id = green_rooms.parent_id WHERE
(green_rooms.parent_id = '4') LIMIT 0, 15 [0m
I dont know why there is this difference, and how to fix the issue of
different queries being issued. BTW is this active scaffold
creating the query or Rails?
White Wizzard
White Wizzard
Do you use acts_as_nested_set plugin or BetterNestedSet?
I ve tried it with BetterNestedSet and the UI seems to work perfect,
but unfortunetly 'lft' and 'rgt' attributes are not set correctly.
Could you please take a look if they are set correctly in your app?
Thanks a lot in advance.
root node has lft = 1 and rgt = 2, which is obviously incorrect. right
has to be 2 * node_num for the root node.
At least as far I know.
--
volker
I used what was built into rails, in my green room model I have
acts_as_nested set. I was not using better nested plugin.
Also I did not use lft and rgt in my database, I omitted them ( due
to ignorance). Anyways it worked for me in production.
White Wizzard
On Nov 12, 11:11 am, "MrBana...@googlemail.com"
ok, I m using the better_nested_set...
and I just had to add the following to my controller:
def after_create_save(record)
record.move_to_child_of record.parent.id unless record.parent.nil?
end
This line will set/update all lft and rgt attribute values.
Just for info...
--
Volker