
现在我有
f.collection_select(:category_ID,@categorIEs,:ID,:name,{:prompt => 'Please select a category'}) 它产生
<select ID="product_category_ID" name="product[category_ID]"> <option value="">Please select a category</option> <option value="7">category one</option> <option value="8">category 2</option></select>
我想要的是
<select ID="product_category_ID" name="product[category_ID]"> <option value="">Please select a category</option> <option value="7">category one</option> <option value="8">category 2</option> <option value="new">..or create a new one</option></select>
这是可能的还是应该循环遍历集合并手动生成选项?
解决方法 你应该可以使用选择.像这样:
f.select(:category_ID,@categorIEs.collect {|p| [ p.name,p.ID ] } + [ [ 'Or create a new one','new' ] ],{:include_blank => 'Please select a category'}) 祝你好运!
总结以上是内存溢出为你收集整理的html – Rails的collection_select帮助方法和最后的“创建项目”选项全部内容,希望文章能够帮你解决html – Rails的collection_select帮助方法和最后的“创建项目”选项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)