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.
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:
construct that model so it contains equivalents for all the fields
from all the tables.
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.
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.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.