Topic: multiple model in a form or wizard between models

It's kind a confusing....


i am creating an application for contacts, depending on the type of contact i should fill different type of data.

So i was thinking in a basic form with checkboxes for the different types of contact, and depending on what i checked i will show the different forms, if i check all i will have all the forms, however i don't know is there any other better way.... hope you can give me good ideas...

Re: multiple model in a form or wizard between models

Create the Model with database columns for all the data you would like to save. Then, when showing the form, use javascript to show/hide the certain sections of the form that you would like to see.

Make sense?

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: multiple model in a form or wizard between models

seems like a functionable idea, the thing will be with low performance and bad database normalization.

low Performance because it will have a lot of columns

bad database normalization because i should have as the following and not all in one single table, but is practically what you said.

table1 contacts
table2 contactTypes
table3 info of each contact type
table 4...n maybe for each contact type

the problem will be adding values for each contact type if each contact type has a different table.

Re: multiple model in a form or wizard between models

Maybe I misunderstood your question. I think I get more of what you're trying to do now.

You have multiple types of contacts, for example: Normal Contact, Work Contact, School Contact. Each of those different types have certain fields related to them, correct?

If so, one way of doing it would be to create 3 models. Users, User Types, and User Data.

#User.rb
has_one :data, :through => :user_types, :class_name => :user_data

#UserType.rb
belongs_to :user
belongs_to :user_data

#UserData.rb
has_one :user, :through => :user_types

You might even be able to get away with this using only 2 models (users and user_data), but this is the first thing that came to my mind.

This way, you can have unlimited users, and user types. The user's type would link the user with their data. You would be able to access user data like so:

# Assuming the user_data model has a "first_name" method
@user = User.find(:id)
@user.data.first_name

Let me know if that helped you at all or if you have more questions

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: multiple model in a form or wizard between models

Thank you Wesf... that really help, i was thinking similar thing ... 3 models so that i can have unlimited users in unlimeted user types.... the only thing remaining.


the diferent types of contact are REALLY different, for example Supplier, Patient, Employee, Referrer... so as you can see each one will have very different kind of fields...

For example for a patient i will have size measure field, blood pressure, and for a supplier discount_code, type of product tha they sell.... i know this will give you more ideas of what i am trying to accomplish

Re: multiple model in a form or wizard between models

Since you're not wanting to have any empty columns in your database, it seems more efficient to have different user roles. Instead of a general "User" model, you would have "Supplier", "Patient", "Employee", "Referrer" etc.

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!