# Problem with \<%=select%\>

**URL:** <https://www.ruby-forum.com/t/problem-with-select/176538>\
**Category:** Rails\
**Created:** [October 1, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/problem-with-select/176538 "2009-10-01T20:18:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 1, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/problem-with-select/176538/1 "2009-10-01T20:18:30Z")

</div>

Hi all,  
Today I have the following:  
\<%= select( “x”, “Y”, { “” =\> “”,“FOO” =\> “F” ,“BAR” =\> “B”}) %\>

Now I have to test each item in the hash against a determined condition  
and display only if the test returns true.How could I do that?

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 1, 2009, 8:48pm UTC](https://www.ruby-forum.com/t/problem-with-select/176538/2 "2009-10-01T20:48:57Z")

</div>

Rafael R. wrote:

> Hi all,  
> Today I have the following:  
> \<%= select( “x”, “Y”, { “” =\> “”,“FOO” =\> “F” ,“BAR” =\> “B”}) %\>
> 
> Now I have to test each item in the hash against a determined condition  
> and display only if the test returns true.How could I do that?

Hash#select() .

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 1, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/problem-with-select/176538/3 "2009-10-01T20:55:54Z")

</div>

Marnen Laibow-Koser wrote:

> Rafael R. wrote:
> 
> > Hi all,  
> > Today I have the following:  
> > \<%= select( “x”, “Y”, { “” =\> “”,“FOO” =\> “F” ,“BAR” =\> “B”}) %\>
> > 
> > Now I have to test each item in the hash against a determined condition  
> > and display only if the test returns true.How could I do that?
> 
> Hash#select() .
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid  
> Marnen,thanks for your answer.  
> What should I change in my code in order to use your solution?

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 1, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/problem-with-select/176538/4 "2009-10-01T21:39:18Z")

</div>

Rafael R. wrote:

> Marnen Laibow-Koser wrote:
> 
> > Rafael R. wrote:
> > 
> > > Hi all,  
> > > Today I have the following:  
> > > \<%= select( “x”, “Y”, { “” =\> “”,“FOO” =\> “F” ,“BAR” =\> “B”}) %\>
> > > 
> > > Now I have to test each item in the hash against a determined condition  
> > > and display only if the test returns true.How could I do that?
> > 
> > Hash#select() .
> > 
> > ## Best,
> > 
> > Marnen Laibow-Koser  
> > [http://www.marnen.org](http://www.marnen.org)  
> > removed\_email\_address@domain.invalid  
> > Marnen,thanks for your answer.  
> > What should I change in my code in order to use your solution?

Read the documentation for Hash#select and all will become clear.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
