ACts_as_nested_set with active scaffold

38 views
Skip to first unread message

White Wizzard

unread,
Nov 7, 2007, 2:26:31 PM11/7/07
to ActiveScaffold : Ruby on Rails plugin
Hi all

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

White Wizzard

unread,
Nov 7, 2007, 3:22:52 PM11/7/07
to ActiveScaffold : Ruby on Rails plugin
Found exactly where my problem is, and I don't know if there is a fix
for it . . .

"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

unread,
Nov 8, 2007, 8:20:00 AM11/8/07
to ActiveScaffold : Ruby on Rails plugin
Found a solution to this problem, for whatever reason it seems that
active scaffold could determine the reverse association fine on the
development machine and on the production it could not. By putting
in config.columns[:children].association.reverse = :parent in my
active scaffold config in the controller I wa sable to get the
relationship working.


White Wizzard

MrBa...@googlemail.com

unread,
Nov 12, 2007, 11:11:41 AM11/12/07
to ActiveScaffold : Ruby on Rails plugin
Hi 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

White Wizzard

unread,
Nov 12, 2007, 2:12:59 PM11/12/07
to ActiveScaffold : Ruby on Rails plugin
Hi Mr.Banabas

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"

MrBa...@googlemail.com

unread,
Nov 13, 2007, 4:19:06 AM11/13/07
to ActiveScaffold : Ruby on Rails plugin
Hi Wizzard,

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

Reply all
Reply to author
Forward
0 new messages