# Drop dwon list prob in creation & validation

**URL:** <https://www.ruby-forum.com/t/drop-dwon-list-prob-in-creation-validation/120387>\
**Category:** Rails\
**Created:** [November 16, 2007, 12:40pm UTC](https://www.ruby-forum.com/t/drop-dwon-list-prob-in-creation-validation/120387 "2007-11-16T12:40:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [November 16, 2007, 12:40pm UTC](https://www.ruby-forum.com/t/drop-dwon-list-prob-in-creation-validation/120387/1 "2007-11-16T12:40:49Z")

</div>

hi

i want to create a drop down list in the where the data of it will be  
taken from a database table. so i cam across the following way. one is  
don in the HTML way and other one is done in the ROR way.

################### 1st one ########################################

 \<% if @password\_recovery\_question\_id == 0 or @password\_recovery\_question\_id == nil %\> Please Selected An Question \<% end -%\> \<% @questions = PasswordRecoveryQuestion.find(:all, :order =\> "question") @questions.each do |questions| %\> selected="selected" \<% end %\>\> \<%= questions.question %\> \<% end %\> 

#################################################################

################### 2nd one ########################################

\<%= @questions = PasswordRecoveryQuestion.find(:all, :order =\> “id”)  
collection\_select(“password\_recovery\_question”, “recovery\_question”,  
@questions, “id”, “question”)  
%\>

######################################################################

here int the second way i found difficult to add a default value to the  
top of the list as “-- SELECT YOUR OPTION --”

Also i did not able find a working method to validate the drop down list  
for weather it has been select or not and display the error msg in front  
of the drop down list in red color.

pls some body help me
