combined view of 2 or more models

15 views
Skip to first unread message

Vishi

unread,
Nov 18, 2014, 9:10:25 PM11/18/14
to ged...@googlegroups.com
Hi 
How can I have a single form view for multiple models. For example I have a model Home and another model Office. How can I have a single /add and and a single /edit view with two sub forms for Home and Office ?

/top/add
-------------------------------------------------
| Create a new Home    | Create a new Office    | 
| homeProperty1 [____] | officeProperty1 [____] | 
| homePropertyn [____] | officePropertyn [____] | 
| [Add]                | [Add]                  | 
-------------------------------------------------


Matthew Eernisse

unread,
Nov 19, 2014, 12:12:33 AM11/19/14
to ged...@googlegroups.com
You can certainly do, but you will have to code it up yourself -- there's no scaffold for this. The scaffolds are just the bare minimum needed to make a CRUD app backed by a RESTful interface.

It's fairly simple if you're using some sort of associations to link the two -- figure out which the owner model is, and post to that "create" action, or if they're not hierarchical, you can create a custom controller which will create both models at once.

Hope that helps.


--
The official community discussion group.
website: geddyjs.org, source: https://github.com/mde/geddy, group: https://groups.google.com/d/forum/geddyjs?hl=en
---
You received this message because you are subscribed to the Google Groups "GeddyJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geddyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vishi

unread,
Nov 19, 2014, 11:10:04 AM11/19/14
to ged...@googlegroups.com
HI Matthew,
It is not hierarchical, and I was trying to create a custom controller. It is straightforward for the index view and I can respond with both homes and offices as below
          self.respond(homes : homes, offices: offices, {template: 'app/views/tops/index'});

But I am strugging to understand how I can implement the create function in the top controller which can create either a home or a office, depending on which subform is filled and clicked.

Note that in the folloing picture, user can either fill the left form to create home or the right form to create office
/top/add
-------------------------------------------------
| Create a new Home    | Create a new Office    | 
| homeProperty1 [____] | officeProperty1 [____] | 
| homePropertyn [____] | officePropertyn [____] | 
| [Add]                | [Add]                  | 
-------------------------------------------------


Reply all
Reply to author
Forward
0 new messages