# Rails 2.3.5/Ruby1.8.7 Collection\_Select Labels with ampersands "&"

**URL:** <https://www.ruby-forum.com/t/rails-2-3-5-ruby1-8-7-collection-select-labels-with-ampersands/183875>\
**Category:** Rails\
**Created:** [February 22, 2010, 8:05am UTC](https://www.ruby-forum.com/t/rails-2-3-5-ruby1-8-7-collection-select-labels-with-ampersands/183875 "2010-02-22T08:05:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbkbali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cc9497/32.png) [@dbkbali](https://www.ruby-forum.com/u/dbkbali)\
**Post date:** [February 22, 2010, 8:05am UTC](https://www.ruby-forum.com/t/rails-2-3-5-ruby1-8-7-collection-select-labels-with-ampersands/183875/1 "2010-02-22T08:05:49Z")

</div>

I am having an annoying problem displaying the labels of a select box  
correctly where there is an ampersand contained within the label  
string.

On a form being rendered with the form\_for helper the  
collection\_select reads data from a Mysql 5.075 database the text  
stored in the database is “Surabaya & Surrounding Areas” when rendered  
and displayed in firefox 3.6 or safari is is displaying as “Surabaya  
%amp; Surrounding Areas”.

The code used to render the select is as follows:

\<%= f.collection\_select :parent\_id, Destination.roots, :id, :name,  
{:include\_blank =\> true} %\>

I have tried adding a h(:name) and also storing && in the database but  
it still will not display the ampersand correctly. Have searched on  
google for what I thought would be a simple solution but cant find  
anything that solves this.

If anyone has a solution it will be much appreciated.

many thanks,

David

---

<div class="post-metadata">

**Author:** ![dbkbali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cc9497/32.png) [@dbkbali](https://www.ruby-forum.com/u/dbkbali)\
**Post date:** [February 22, 2010, 9:30am UTC](https://www.ruby-forum.com/t/rails-2-3-5-ruby1-8-7-collection-select-labels-with-ampersands/183875/2 "2010-02-22T09:30:06Z")

</div>

You can try to change “Surabaya & Surrounding Areas” in your database to  
“Surabaya & Surrounding Areas”

Best Regards,  
Boby Ertanto

---

<div class="post-metadata">

**Author:** ![dbkbali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cc9497/32.png) [@dbkbali](https://www.ruby-forum.com/u/dbkbali)\
**Post date:** [February 22, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/rails-2-3-5-ruby1-8-7-collection-select-labels-with-ampersands/183875/3 "2010-02-22T18:06:59Z")

</div>

Boby,

tried that earlier and that produced “Surabaya &amp; Surrounding  
Areas”.

It looks like I might have to write a custom helper method or hack the  
form\_for helper method, which I was hoping to avoid.

If you or another reader has a better way your feedback would be much  
appreciated.

Thx anyway for your suggestion.

David

---

<div class="post-metadata">

**Author:** ![dbkbali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cc9497/32.png) [@dbkbali](https://www.ruby-forum.com/u/dbkbali)\
**Post date:** [February 22, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/rails-2-3-5-ruby1-8-7-collection-select-labels-with-ampersands/183875/4 "2010-02-22T18:45:37Z")

</div>

Problem solved after debugging further realized my select option  
values were being created in Javascript from an erb file, the problem  
was created by using \<%= %\> instead of \<%- %\> when creating the  
javascript to send to the client. Learning something new everyday!
