我尝试了:include_blank => true,但是没有用。

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

如果我需要将其添加到集合中,您将如何做?

最佳答案

我认为您想要这种格式:

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

顺便说一句:假设Modle被假定为模型。要使用collection_select使用:
collection_select(:model, :model_id, Model.all, :id, :name, :prompt => true)

关于ruby-on-rails - 在options_for_select标记的选择列表中包括第一项的空白,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6710965/

10-12 05:25