html – Rails的collection_select帮助方法和最后的“创建项目”选项

html – Rails的collection_select帮助方法和最后的“创建项目”选项,第1张

概述是否可以添加< option>在< select>的结尾处用collection_select帮助程序创建? 现在我有 f.collection_select(:category_id , @categories, :id, :name, {:prompt => 'Please select a category'}) 它产生 <select id="product_category_id" na 是否可以添加< option>在< select>的结尾处用collection_select帮助程序创建?

现在我有

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帮助方法和最后的“创建项目”选项所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1091715.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存