# Creating an HTML select

**URL:** <https://www.ruby-forum.com/t/creating-an-html-select/112234>\
**Category:** Rails\
**Created:** [August 16, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/creating-an-html-select/112234 "2007-08-16T17:53:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [August 16, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/creating-an-html-select/112234/1 "2007-08-16T17:53:51Z")

</div>

Hi, I use the following code in a view to show a list of states inside a  
form but I get not result, I mean I get no errors nor the expected HTML  
code that should be something like \<option …

```
@states = State.find(:all, :order => "name")
collection_select(:firm, :state_id, @states, :id, :name)

```

Can anyone please tell me why?

---

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [August 16, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/creating-an-html-select/112234/2 "2007-08-16T18:18:37Z")

</div>

Are you wrapping the collection\_select code in \<%= %\> tags?

Nik N. wrote:

> Hi, I use the following code in a view to show a list of states inside a  
> form but I get not result, I mean I get no errors nor the expected HTML  
> code that should be something like \<option …
> 
> ```
> @states = State.find(:all, :order => "name")
> collection_select(:firm, :state_id, @states, :id, :name)
> 
> ```
> 
> Can anyone please tell me why?

–  
Sincerely,

William P.

[http://www.billpratt.net](http://www.billpratt.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [August 16, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/creating-an-html-select/112234/3 "2007-08-16T19:20:25Z")

</div>

Hi William,  
I’m a PHP developer and I’m testing RoR so I thought \<% … %\> was right  
when writing more than one line of code! I just added “=” after “\<%” and  
it worked.  
Thanks a lot! These are those little errors that can make you waste a  
lot of time!  
Nik

William P. wrote:

> Are you wrapping the collection\_select code in \<%= %\> tags?
> 
> Nik N. wrote:
> 
> > Hi, I use the following code in a view to show a list of states inside a  
> > form but I get not result, I mean I get no errors nor the expected HTML  
> > code that should be something like \<option …
> > 
> > ```
> > @states = State.find(:all, :order => "name")
> > collection_select(:firm, :state_id, @states, :id, :name)
> > 
> > ```
> > 
> > Can anyone please tell me why?
> 
> –  
> Sincerely,
> 
> William P.
> 
> [http://www.billpratt.net](http://www.billpratt.net)  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [August 16, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/creating-an-html-select/112234/4 "2007-08-16T21:08:59Z")

</div>

No problem. \<% %\> should be around code that you do not want the output  
added to the rendered page (adding a dash at the end like -%\> will  
suppress the newline) and \<%= %\> goes around code that will generate  
output to be included in the rendered page. Hope this helps you.

Nik N. wrote:

> > Are you wrapping the collection\_select code in \<%= %\> tags?
> > 
> > > Can anyone please tell me why?

–  
Sincerely,

William P.

[http://www.billpratt.net](http://www.billpratt.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [August 16, 2007, 10:28pm UTC](https://www.ruby-forum.com/t/creating-an-html-select/112234/5 "2007-08-16T22:28:16Z")

</div>

Yes, very clear.  
Thanks again.
