Nested scaffold help

32 views
Skip to first unread message

MichaelLatta

unread,
Mar 17, 2007, 10:50:45 PM3/17/07
to ActiveScaffold : Ruby on Rails plugin
I saw a mention to the need for a controller for a nested scaffold.
This is news to me, and may be part of why the nested lists seem so un-
controllable.

Any tutoral on how to set this up would be appreciated. I currently
have one controller for an acts_as_tree model type. This may be
resulting in the same controller being used for both the top level
list and the nested list. How do I change that so I can have a
separate config for the nested list?

Lance Ivy

unread,
Mar 17, 2007, 11:47:39 PM3/17/07
to actives...@googlegroups.com
Hmm, this is a peculiarity with self-referential associations that we haven't considered. I'm thinking we'll take a look at common acts_as_* plugins and try to provide support in a post-1.0 release.

With acts_as_tree, though, I'm not sure that ActiveScaffold is the proper UI altogether. I mean, shouldn't the UI be fully treelike? How is the basic list approach useful?

Michael Latta

unread,
Mar 17, 2007, 11:54:09 PM3/17/07
to actives...@googlegroups.com
It is useful in that it can be produced with very little effort in the early stage of a project.  I will probably replace it once we get things going.  But, since it is an admin type screen not for end-users it may never make the priority.  Of course what I really want is to have active scaffold support tree type models :-)

For the case where a list is more what you had in mind.  Is there a way to control the configuration of the nested lists?  Do I create an action or a separate controller for the nested lists?  If so how?

Michael



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to actives...@googlegroups.com
To unsubscribe from this group, send email to activescaffol...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---


Lance Ivy

unread,
Mar 18, 2007, 12:03:03 AM3/18/07
to actives...@googlegroups.com
All I can think of to control the columns in the nested scaffolds independently of the columns in the parent scaffold is some kinda hackery where you create two models for the same table. Then set up the child association to use the second model. Then you can create a *controller* for the second model, and set up ActiveScaffold on that controller. Now you have two configurations.

Yeah. Hackery.

Oh, a better hack could involve a before_filter on your controller. In the before_filter, you can re-edit the ActiveScaffold configuration on the fly (e.g. active_scaffold_config.list.columns = [...]). Just watch for some kind of URL param to distinguish between the parent/child, and redefine the column list. I have no idea what kind of complications you might find with this method, but it's sure powerful.

Someone has got to make a good prototyping UI for trees. It's on my list of plugins I want, and if it doesn't exist by the time I get there, well, I'll have to make it. Woooo!

Michael Latta

unread,
Mar 18, 2007, 12:11:15 AM3/18/07
to actives...@googlegroups.com
Thanks for the help.  Those kind of hacks seem more trouble than they are worth however.  This is supposed to be easier than custom UIs.  I will probably just do something simple for the time beeing and deal with it later.

Michael


Michael Latta

unread,
Mar 18, 2007, 1:32:30 PM3/18/07
to actives...@googlegroups.com
Now back to our story...

In a more normal case where the top level list is one type and the children are another type how do I control what is presented in the nested form?  I can not currently even get simple parent/detail screens working because all my child classes have :through associations that are killing AS.  For those cases where I have simple has_many without :through I would still like to get this working.  How do I setup a separate controller for the child scaffold?

Michael

Lance Ivy

unread,
Mar 18, 2007, 2:27:59 PM3/18/07
to actives...@googlegroups.com
If a user :has_many user_groups, then the nested scaffolds visible from the UsersController would by configured by the UserGroupsController.

It sure would be nice if it were more straightforward. For instance, if you could store configuration on the model class and then use/customize it on the controller. Maybe I'll take a look at how that might work tomorrow.

Michael Latta

unread,
Mar 18, 2007, 3:14:00 PM3/18/07
to actives...@googlegroups.com
Thanks for the support.  It would help a great deal if the documentation clearly stated this for nested scaffolds.  But, having the controller strictly selected by name is a problem.  I would rather see something like users_usergroups_controller so that I can present a UserGroup differently if it is nested or top level.  Or, are you saying it is by the association name?  Still it should include the source type name in case of association name collisions.  For example I will have many "children" associations with different content.  Or even better yet.  Have the parent controller return a controller instance for the nested association from a method like <association>_controller then I can configure the controller as I want.  And it should take an argument of the enclosing instance so it can be context specific!

Michael



Lance Ivy

unread,
Mar 18, 2007, 3:25:05 PM3/18/07
to actives...@googlegroups.com
Just added a section to activescaffold.com/docs/api-nested.

You know, actually, these configuration objects could be created and saved independently of any model or controller. Perhaps we could support the ability to create and use arbitrary configuration objects for nested scaffolds, something like what you described.

Gotta figure out precisely what we want to support, though. If we've got too many ways to solve a problem then things get unmaintainable.

Michael Latta

unread,
Mar 18, 2007, 6:12:04 PM3/18/07
to actives...@googlegroups.com
I agree.  I much prefer the Rails approach of being opinionated about how a problem should be solved and encouraging that it be done that way.  But, we need a solution to allow nested scaffolds to be configured independently of other contexts.  I look forward to seeing what you settle on.  Given what you have described I will most likely make all my top level controllers functional names rather than class names, and let the nested scaffold controllers be class named.

Michael


Michael Latta

unread,
Mar 18, 2007, 11:50:34 PM3/18/07
to actives...@googlegroups.com
Lance,

I have been able to deal with one level of nesting by naming the top level controlers something other than a class name like "security" for users and groups, and "customer_contacts" for the top level customer controller.  Then I can use the class named controllers for the nested lists.

I would really hope that your solution involves controllers for the nested lists as that allows me to hang methods off that controller that are unique to that context.  So the method of asking the parent controller to provide a controller instance for each nested association would be perfect.  Of course you would need to produce a default implementation of that method which might use a convention that included the parent controller name as in #{parent_controller}_#{nested_association}_controller.  Note that I had the association not the class name.  That allows 2 associations with the same class to have different controllers under the same parent controller.   You could also search for this then fall back to a class based controller.

Michael
Reply all
Reply to author
Forward
0 new messages