【发布时间】:2015-12-09 11:09:12
【问题描述】:
我想在我的应用程序中实现依赖字段。为此,我使用了dependent-fields-rails gem。我已经用this tutorial 设置了所有内容。好东西:它有效。有点儿。在我的品牌模型中,我列出了阿迪达斯、耐克等品牌...
现在我的两个挑战:
- 我不知道必须在
data-option-value=" "字段中填写什么,因为如果完全选择了品牌而不是特定品牌,我想显示类别的选择表单。如果我在data-option-value="Adidas"之类的字段(硬编码)中输入了一个值,那么只有在我从品牌下拉列表中选择了“阿迪达斯”时,才会出现 category_select 表单。 - 我只想显示在步骤 1 中选择的品牌的匹配类别。我的组模型还包含品牌记录,因此我可以将类别与品牌匹配。
为了更清楚一点:
- 品牌模型包含阿迪达斯、耐克等公司...
- 组模型包含鞋类、衬衫等类别...
这是我得到的:
<div class="form-group">
<%= f.label :brand %>
<%= f.select(:brand, Brand.pluck(:company).uniq, {prompt:true}, {class: 'form-control'}) %>
</div>
<div class="form-group js-dependent-fields" data-select-id='warehouse_brand' data-option-value="Adidas">
<%= f.label :category %>
<%= f.collection_select(:category, Group.all, :brand, :name1, {prompt:true}, {class: 'form-control'}) %>
</div>
有什么想法吗?提前非常感谢!
【问题讨论】:
标签: ruby-on-rails