:select_tag的提示不会出现在框中

时间:2011-05-06 22:02:24

标签: ruby-on-rails select

使用此代码:

= f.select :how_did_you_hear, HOWD_YOU_HEAR, {:prompt => "HQCard found by"}, :style => "width: 142px;"

提示被视为空白,第一个选择是“HQCard found by”。然后是一个空格和项目集合。

如何在默认选择框中将其显示为默认值?

2 个答案:

答案 0 :(得分:6)

易于使用:include_blank

f.select :how_did_you_hear, HOWD_YOU_HEAR, :style => "width: 142px;", {:include_blank => '- Select HowD U Hear -' }

Documentation

答案 1 :(得分:2)

哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇

因此,如果您使用非常规allow_blankselected,则可以使用:

= f.select :how_did_you_hear, HOWD_YOU_HEAR, { :include_blank => "HQCard found by", :selected => "HQCard found by"}, :style => "width: 142px;"