Reputation: 32020
In my signup I have Choose a Question
drop-down:Code below
<%= f.select("question_id", Question.all.collect {|p| [ p.body, p.id ] }])) %>
and I want to get the output like below
<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>
With the code f.select
I could get all questions from database but How can I add Choose a question ...
option to my drop-down? which will be shown on default and could give output as above HTML code
Upvotes: 2
Views: 450
Reputation: 2859
Another option would be:
= f.select "question_id", Question.all.collect {|p| [ p.body, p.id ] }, include_blank: "Choose a question ..."
Upvotes: 2
Reputation: 608
Have you tried to use the :prompt => "Choose a question ..."
option?
I hope help you!
Hugs!
Upvotes: 4