Ruby on rails - mutual exclusion
I have a model "categories": t.string :c1 开发者_StackOverflow社区 t.string :c2 t.string :c3
A category could be: Ferrari, red, maxspeed. I created some categories, and I want to built a form where I can choose how to send a category: If I choose c1 then I want to choose c2 ONLY from all the categories who have c1 like my choise; for example If I choose "ferrari" I can only choose the colours avaiable for that type of car. How can I do that, starting from this code?
<div class="field">
<%= f.label :brand %>
<%= select (:request, :brand, Category.all.collect {|category| [category.c1]}) %>
</div>
<div class="field">
<%= f.label :color %>
<%= select (:request, :color, Category.all.collect {|category| [category.c2]}) %>
</div>
<div class="field">
<%= f.label :maxspeed %><
<%= select (:request, :maxspeed, Category.all.collect {|category| [category.c3]}) %>
</div>
I've found two solutions to build a chained menu:
from railcasts: http://railscasts.com/episodes/88-dynamic-select-menus javascript: http://www.dynamicdrive.com/dynamicindex1/chainedmenu/chainedmenu.html#note
Hi I think you have to do AJAX request when first field was selected and update second select with proper values
精彩评论