Help needed on Select Form

Dear all,

I am pretty new to ruby on rails and I am supposed to create a form with a few drop down options. The first drop down option will affect the result in the data appearing in the drop down option for the second field. E.g. If user select mobile phone as their device, the next drop down will show the different OS of the phone such as Android, Symbian etc.. and not OS of a computer.

Hope to receive replies/help on this.

Many Thanks in advance.

Deb Liew wrote:

Dear all,

I am pretty new to ruby on rails and I am supposed to create a form with a few drop down options. The first drop down option will affect the result in the data appearing in the drop down option for the second field. E.g. If user select mobile phone as their device, the next drop down will show the different OS of the phone such as Android, Symbian etc.. and not OS of a computer.

Hope to receive replies/help on this.

Many Thanks in advance.

Hi,

You can use OnChange on the First select Box and call a remote function like <%= collection_select :device, :id, @devices, :id , :name, {}, {:onchange => remote_function( :update => "operating_system", :url => { :controller => "devices", :action => "get_os"}, :position => "replace", :with => "'device_id='+this.value") } %> And have an element say div with id="operating_systems"

In devices controller,action get_os Find out @os (params[:device_id] will give you the device's id from which i suppose you can get the list of OS for the device)

Have a partial called _get_os.html.erb which will have the select box for the OS <%= collection_select :os, :id, @os, :id , :name %>

This is one of the many ways you can implement this functioanlity.Hope You find this useful.

Hi,

Thank you for your reply.

Can I assume the method you stated is used when the values are inside the database? Or does it work the same if it is not?

Thanks, once again.

Charanya Nagarajan wrote:

Hi,

According to my consideration, You will need the databases to be filled.I assumed that You have a table called OS and Device.And Os and device tables are associated to each other like OS belongs to Device That is how from the device's id we can get the list of OS for that device in @os in the controller.

Regards, Charanya Nagarajan

Deb Liew wrote: