Multi model form - please, give me some idea

Hi.

I would like to create a form that uses several models depending on the drop-down list.

For example:

I have two tables:

advertisements

id | title | date | description

cars

id | id_advertisements | car_brand | engine_capacity

computers

id | id_advertisements | processor | graphic_card

And in a form when I select option "cars" from the drop down list I would like to load a "cars" model, but when I select "computers" then load "computers" model.

How to do it?

First solution:

Display your drop-down box

Render Car Model Form (and hide it using style=“display:none”). Form’s action attribute should be an URL linking to car/create

Render Computer Model Form [size=2](and hide it using style=“display:none”)[/size][size=2]Form’s action attribute should be an URL linking to[/size][size=2] [/size]computer/create

[size=2]

[/size]

[size=2]Put onchange event on your dropdown box, and check what user clicked. If user clicked on cars, then using jQuery you can show Car Form. If user selected Computer in drop-down, then show Computer Form. [/size]

[size=2]

[/size]

[size=2]Second solution[/size]

[size=2]

[/size]

[size=2]Display your drop down[/size]

Onchange event will make an AjaxCall which will return Car Form or Computer Form.

When user submits a form, a proper controller will be called

Cheers

[size=2]

[/size]

Could you give me example code to second solution?

I was looking for and I tried to do it, but I have no idea.