2012-01-31 46 views
2

在我注册我有Choose a Question下拉:代码如下如何添加默认选择选择一个字段选项到我的下拉导轨?

<%= f.select("question_id", Question.all.collect {|p| [ p.body, p.id ] }])) %> 

,我想要得到的输出像下面

<select name="question" id="login_fields_question" class="signup_fields" > 
<option value="choosequestion" selected="selected" style="font-style:italic;">Choose a question ...</option> 
<option value="1"> What is your pet name?</option> 
<option value="2">What is the name of your best friend from childhood?</option> 
<option value="3">What was the name of your first teacher?</option> 
<option value="4">What is the name of your manager at your first job?</option> 
<option value="5">What was your first phone number?</option> 
<option value="6">What is your vehicle registration number?</option> 

随着代码f.select我能得到的所有问题从数据库,但我怎样才能添加Choose a question ...选项,我的下拉?这将显示默认情况下,可能会给出如上输出HTML代码

回答

5

您是否尝试过使用:prompt => "Choose a question ..."选项?

我希望能帮到你!

拥抱!

2

另一种选择是:

= f.select "question_id", Question.all.collect {|p| [ p.body, p.id ] }, include_blank: "Choose a question ..."