Using SmartClientJS 10.0, but the question is not related to that particular version (it's more of a architectural question).
I'm using a RubyOnRails back-end and want to create a Customer form. Customer has an id, name and other fields. But it also has detail records for (zero or more) addresses. I would like to create a form that POSTs everything in one request, without the need for a customer record to exist before addresses can be added in the form. Of course, when saving to the database, the customer gets created first and with the created id, the addresses will be saved to the database as well. This can all be done in one transaction.
I've more or less created this with the CanvasItem example. When opening the form, I request JSON data that looks this:
I have troubles in POSTing the data and Rails treating the addresses as array. It suspect it needs "[]" in the name. I'm not sure yet, but if so, I don't know if that's possible and if it is, how? I've tried giving the form item with the grid a name that included the "[]" but the GET data probably should have that name as well and that's "hard" to program on the server (with "hard" I mean in a "Rails friendly way").
But already being busy with this problem for hours (if not days) already, it made me wonder if this is the approach I need to chose. I could use any kind of advice, my main goal is to avoid the necessity of creating the customer beforehand to be able to create addresses.
Right now, I don't use SmartClient's foreignKey solution, but maybe that's the way to go. I basically create a piece of JavaScript that defines all data sources from RubyOnRails "meta" data in my model classes (but that's off scope I guess).
Anyone experience with Rails and SmartClient that could give advice? Thanks in advance.
I'm using a RubyOnRails back-end and want to create a Customer form. Customer has an id, name and other fields. But it also has detail records for (zero or more) addresses. I would like to create a form that POSTs everything in one request, without the need for a customer record to exist before addresses can be added in the form. Of course, when saving to the database, the customer gets created first and with the created id, the addresses will be saved to the database as well. This can all be done in one transaction.
I've more or less created this with the CanvasItem example. When opening the form, I request JSON data that looks this:
Code:
{ "status": 0, "response": { "data": { "id": 1, "name": "John Doe", "addresses": [ { "id": 1, "street": "Down town street", "house_number": "1", "type": "shipping" }, { "id": 2, "street": "Up town lane", "house_number": "2", "type": "billing" } ] } }
But already being busy with this problem for hours (if not days) already, it made me wonder if this is the approach I need to chose. I could use any kind of advice, my main goal is to avoid the necessity of creating the customer beforehand to be able to create addresses.
Right now, I don't use SmartClient's foreignKey solution, but maybe that's the way to go. I basically create a piece of JavaScript that defines all data sources from RubyOnRails "meta" data in my model classes (but that's off scope I guess).
Anyone experience with Rails and SmartClient that could give advice? Thanks in advance.
Comment