在 options_for_select 标签的选择列表中包含第一项的空白 [英] Include blank for first item in select list in options_for_select tag

查看:18
本文介绍了在 options_for_select 标签的选择列表中包含第一项的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过 :include_blank =>是的,但它不起作用.

I tried :include_blank => true, but it didn't work.

<select>
    <%= options_for_select Model.all.collect{|mt| [mt.name, mt.id]} %>
</select>

如果我需要将它添加到集合中,你会怎么做?

If I need to add it to the collection, how would you do that?

推荐答案

我想你想要这种格式:

select("model_name", "model_id", Model.all.collect {|mt| [ mt.name, mt.id ] }, {:include_blank => 'name of your blank prompt'})

顺便说一句:假设模型应该是模型.要使用 collection_select:

BTW: was assuming Modle was suppose to be Model. To use using collection_select:

collection_select(:model, :model_id, Model.all, :id, :name, :prompt => true)

这篇关于在 options_for_select 标签的选择列表中包含第一项的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆