Topic: Best way to create multiple-table-row entry form for my app?

I'm new to rails, but have already built a working application up until this point.

Basically I need an input form that can insert multiple rows into the database in one go, and hopefully display data in the same way (once the db is populated). The form can be a view/edit/update form all-in-one. If there is no db record available for a cell it should be an empty cell that creates a new record upon form submit.

I've drawn a picture to show the sort of form I am trying to achieve (and to show how it relates to the db table). In my head it seems like it would be rather complex to make it work (basically generating a virtual 'table' input structure that is not actually replicated in the database). However it would be good for the user.

The purpose of this form is to store 'adjustment' settings for a given 'shock' and 'bike' already chosen by the user. The weight (rider weight) is a preset range. The adjustments vary depending on shock choice, thus number + name of columns are dynamic.

http://i43.tinypic.com/521hlt.png

Any tips or suggestions on the best/easiest way to make this work?
I am flexible on the layout and design of the form, the easier to code the better.

Appreciate any thoughts, especially any rails specific commands or goodies I should look into that might make life easier.

Last edited by udi (2012-04-13 22:50:19)

Re: Best way to create multiple-table-row entry form for my app?

Does anyone who is not a spam bot have any suggestions? smile

Edit - got the form working sweetly, it was worth posting a thread just to get things straight in my own head. Have got the data through the POST and organised neatly at the other end, now just have to submit multiple rows into the database.

The other quick question I have is, is there a simple way to check if the query needs to be UPDATE or INSERT? I don't have the benefit of a single-column identifier for each record in this table, and the same form (and thus controller method) will be dealing with both 'new' and 'edit' recordsets.

Does this mean I'm doomed to checking manually for a record's existence before updating or inserting based on that? I'm probably going to go down this road anyway, but thought I'd ask.

Last edited by udi (2012-04-19 14:23:12)

Re: Best way to create multiple-table-row entry form for my app?

rails knows if records are new or existing smile

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Best way to create multiple-table-row entry form for my app?

Rails is able to determine that automatically based on the HTTP verb used by the form. If the form uses POST, it uses the create action of the controller. If the form uses PUT, it uses the update action.

If you want to explicity check if a record is new though, new_record? is the method you want.

Change is a vector. You can have all the change in the world, but if it doesn't go in the right direction, what good is it? | techonamission.com

Re: Best way to create multiple-table-row entry form for my app?

Hey Udi,I'm trying to create a same sort of form could you tell me how you got it working?Or share with me a bit of your code, I'm especially curious in the code for the views.Thanks a lot in advance.Grts Niels