Forum: Ruby on Rails dynamically showing data based on different selection

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C3bdd57da4de3560baac7b267eb32012?d=identicon&s=25 surfman (Guest)
on 2007-06-11 04:30
suppose there is a selection list that has different selections, I want
to show different items to my users based on each different selection.

say, there is selection list that has breakfast, lunch, dinner, when a
user chooses breakfast, the page will show all items for breakfast, for
instance, bread, milk, sausage, when the user chooses lunch, the same
page will show beef, soup, noodles, etc.

is there any fast way to do this? thanks.
B875458d21d2f16392b9a1f5dbd99d42?d=identicon&s=25 (Guest)
on 2007-06-11 07:35
(Received via mailing list)
I have the same situation where the users selects a room, then
storage , then sub compartment each with it's own unique dataset.
[Room]\/   [Storage type]\/   [Sub storage]\/   [Substorage]\/

The storage model uses the "acts_as_tree" for hierarchy.

it's a patch (if there is a better way to do it I'll be glad to
refactor it):

<% if !storages.empty?%>
<% type_url = "'/storages/get_selected_type/' +
this[this.selectedIndex].value "%>
<% select_array = storages.collect {|storage| [ storage.type_and_name, ]}%>
<%=select "storage","id", select_array,
    options = {:prompt => "- Select -"},
    html_options={:onChange => "new Ajax.Request(#{type_url},
                  { asynchronous:true,
                                      evalScripts:true ,
                Element.hide('storage_children'); },

<%= spinner_tag("spinner_storage") %>

I am creating an Ajax request on the change event, this calls returns
the next selection dropdown.
(p.s. the spinner tag is just an helper method to return a spinner).

Hope this helps.
Jonathan Gross.
This topic is locked and can not be replied to.