To get the id value from parent table to child table

Hi
Im using 5 tables and one parent table and 4 child tables

To get the id value from parent table to child table.To store the values
in
databases and display the bugs

parent table id is compare to child table is resortid
code
using save page

@resort_contact.resortid=@resort_basic.id
child table id=parent table id

To give any idea and any link
Thanks

Basic vanilla Rails…

Your parent table (resort_basic?) should have an ID column.

All your child tables (like resort_contact?) should include a field
named resort_basic_id of type integer.

class resort_basic
has_many :resort_contacts
etc, etc
end

class resort_contact
belongs_to :resort_basic
end

You can:
→ use a hidden field on the resort_contact form to store the
resort_basic_id, setting this value in the resort_contact controller’s
new method if the vlaue is known, then retrieve that from the params in
the create method

→ or the resort_contact form may include a droplist field where you
choose the resort_basic ID as part of creating the resort contact

→ or some other more advanced methods, but the nature of your question
leads me to believe that you should stick to the basics for now.

As for links:

http://api.rubyonrails.org/
or

There are tons of examples out there that don’t have to be repeated
here.

Hi
Im using the 5 tables+5 views+one model+one controller.so i can’t
understand and give any idea

balaji

Balaji Rajagopalan wrote:

Hi
Im using the 5 tables+5 views+one model+one controller.so i can’t
understand and give any idea

balaji

Generally for Rails, 1 db table == 1 Rails model.

If you’re trying to do this with a single model, I assume that you’ll
have to:

  1. construct that model so it contains equivalents for all the fields
    from all the tables.
  2. Pass this model from view to view, editing some fields, and keeping
    the rest as hidden fields on each form. Like form1 shows fields 1 and 2,
    hides fields 3 through 10. Form 2 shows fields 3 and 4, hides 1, 2, 5
    through 10, etc.
  3. the controller has to know which form submitted so it knows what to
    do next… go to the next form, or try to save the data. A variable
    stored in a hidden field should suffice for that, @current_step or
    something like that.
  4. When you finally submit from view 5 and go to save, extract the
    fields for the parent table and save that record. Re-read that record to
    get its id, and put that in the parent id field for each of the sets of
    fields you have to save to your child tables. And wrap it all in a
    transaction so you can rollback if the third or fourth model fails
    validation.