这似乎是一个非常受欢迎的问题,尽管我还没有找到适合我的教程或线程。我在表单中有两个下拉菜单,团队类型和用户角色,其中用户角色取决于团队类型。团队类型的选项作为数组存储在模型中,因为只有 5 个选项(艺术家、场地、发起人、独立、其他)。我想做的是从模型中获取用户角色的选择,并根据团队类型选择正确的数组。这可能吗,还是我需要为每个团队类型创建模型并将 ID 传递给连接表以选择正确的用户角色?谢谢你。
模型
class WaitingList < ActiveRecord::Base
COMPANIES = ['—Select—', 'Artist Team', 'Venue Team', 'Promoter', 'Independent', 'Other']
ARTIST_TEAM = ['-Select-', 'Artist', 'Manager', 'Tour Manager', 'Production Manager', 'Agent', 'Other']
VENUE_TEAM = ['-Select-', 'Artist Liason', 'Stage Manager', 'Production Manager', 'Owner', 'Other']
PROMOTER = ['-Select', 'Talent Buyer', 'Other']
INDEPENDENT = ['-Select', 'Agent', 'Photo/Video', 'Tour Manager', 'Manager', 'Other']
end
形式
<div class="form--col">
<label>Team Type</label>
<div class="dropdown-wrapper">
<%= f.collection_select :company_type, WaitingList::COMPANIES, :to_s, :to_s, {:include_blank => false}, {:class => "form--dropdown -team_type"} %>
</div>
</div>
<div class="form--col -inactive">
<label>Main Role</label>
<div class="dropdown-wrapper">
<%= f.collection_select :user_type, WaitingList::USERS, :to_s, :to_s, {:include_blank => false}, {:class => "form--dropdown", :disabled => "disabled"} %>
</div>
</div>