# Select\_tag

**URL:** <https://www.ruby-forum.com/t/select-tag/186977>\
**Category:** Rails\
**Created:** [April 15, 2010, 5:56am UTC](https://www.ruby-forum.com/t/select-tag/186977 "2010-04-15T05:56:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![krismartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@krismartin](https://www.ruby-forum.com/u/krismartin)\
**Post date:** [April 15, 2010, 5:56am UTC](https://www.ruby-forum.com/t/select-tag/186977/1 "2010-04-15T05:56:40Z")

</div>

a stupid question from a newbie…

how can i populate my select\_tag with the values from a SELECT DISTINCT  
statement?

thanks for bearing with my stupidity…

---

<div class="post-metadata">

**Author:** ![krismartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@krismartin](https://www.ruby-forum.com/u/krismartin)\
**Post date:** [April 15, 2010, 10:26am UTC](https://www.ruby-forum.com/t/select-tag/186977/2 "2010-04-15T10:26:44Z")

</div>

You should investigate collection\_select

> **[ActionView::Helpers::FormOptionsHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M001625)**
>
> Provides a number of methods for turning different kinds of containers into a set of option tags.

Hope this helps,  
Christophe  
Le 15 avr. 2010 à 05:56, Kris Mojica a écrit :

---

<div class="post-metadata">

**Author:** ![krismartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@krismartin](https://www.ruby-forum.com/u/krismartin)\
**Post date:** [April 16, 2010, 4:52am UTC](https://www.ruby-forum.com/t/select-tag/186977/3 "2010-04-16T04:52:34Z")

</div>

thanks a lot! so it’s collection\_select… i’ll try this one out. thanks  
again. ^^

Christophe D. wrote:

> You should investigate collection\_select  
> [ActionView::Helpers::FormOptionsHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M001625)
> 
> Hope this helps,  
> Christophe  
> Le 15 avr. 2010 ï¿½ 05:56, Kris Mojica a ï¿½crit :

---

<div class="post-metadata">

**Author:** ![krismartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@krismartin](https://www.ruby-forum.com/u/krismartin)\
**Post date:** [April 16, 2010, 7:14am UTC](https://www.ruby-forum.com/t/select-tag/186977/4 "2010-04-16T07:14:32Z")

</div>

Hai Kris ,

I am also a newbie in ROR.Hope this will help you…

case 1:(If your table has only distinct elements, go for  
collection\_select)

eg.  
Here we hav a “District” table with fields “id” and “name”  
index.html.erb  
\<%= collection\_select(nil, :district\_id, @districts, :id,  
:name,{:include\_blank=\>‘All’},{})

controller  
def index  
@districts=District.find(:all)  
end

case 2:(If your table has duplicate elements and you want only distinct  
elements to be populated in it)

eg:  
Here we hav a “Station” table with one field as “district”

index.html.erb  
\<%= select(:post,:district, @districts,{:include\_blank=\>‘All’},{} )%\>  
controller  
def index  
@districts = Station.find(:all, :select=\>‘district’, :order  
=\>“district”).map{ |t| t.district }.uniq  
end
