# Collection\_select is quoting my text\_method text?

**URL:** <https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093>\
**Category:** Rails\
**Created:** [September 26, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093 "2006-09-26T19:29:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [September 26, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/1 "2006-09-26T19:29:40Z")

</div>

I have a table that contains currencies I support which has the  
columns:  
id,  
ch (the character to display when showing currency)  
name (the human name of the currency …)

This table is currently loaded with these values:

currencies:

Name ch

* * *

U.S.D $  
Euro &euro  
G.B.P. &pound

I created a method in my ‘currency’ model called ‘menustr’ which I use  
in collection\_select to show the currency options:

def menustr  
return ch + " " + name  
end

I then use this in my form template:

```
<td><label for="customer_def_cur_pref">Default Currency:

```

\<%= collection\_select(“customer”, :def\_cur\_pref, @zcurtype,  
:ch, :menustr) %\>

where @zcurtype is an array containing all the currencies in the  
currencies table.

Instead of putting the pretty html version of &pound and &euro in my  
pull down menu, collection\_select’s form is quoting them and I still  
see the “&pound” and “&euro” text.

Anyone have a way to work around this?

Thanks!

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [September 27, 2006, 3:04am UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/2 "2006-09-27T03:04:23Z")

</div>

dmack wrote:

> Name ch  
> end
> 
> Instead of putting the pretty html version of &pound and &euro in my  
> pull down menu, collection\_select’s form is quoting them and I still  
> see the “&pound” and “&euro” text.

Append a semicolon to the values in your table that are HTML symbols.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [September 27, 2006, 3:56am UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/3 "2006-09-27T03:56:27Z")

</div>

Mark Reginald J. wrote:

> > ```
> > return ch + " " + name
> > 
> > ```
> > 
> > currencies table.
> > 
> > Instead of putting the pretty html version of &pound and &euro in my  
> > pull down menu, collection\_select’s form is quoting them and I still  
> > see the “&pound” and “&euro” text.
> 
> Append a semicolon to the values in your table that are HTML symbols.

Thanks for the response. I have the semi-colon on the end of my values  
for ‘ch’ in my currencies table. If I list my table using the default  
scaffolding, I get what I want:

Listing currencies (sorry for the formatting)  
Name Ch Menustr Actions  
USD $ $; USD Show Edit Destroy  
Euro ? ?; Euro Show Edit Destroy  
GBP £ £; GBP Show Edit Destroy

However, when I populate a pull-down menu using collection\_select, the  
symbol reverts back to either &pound or &euro which doesn’t look as  
pretty ☹

My controller does this:

def new  
@customer = Customer.new  
@zcurtype= Currency.find(:all)  
end

and the chunk in the form template does this for the pull-down:

Default Currency:   
\<%= collection\_select(“customer”, :def\_cur\_pref, @zcurtype, :ch,  
:menustr) %\>

… Looking at the generated html, you can see the &amp … prefixes  
on the code plus the extra semi-colon I added to see if it would help  
🙂

Default Currency:   
  
$; USD  
&euro;; Euro  
&pound;; GBP

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [September 29, 2006, 6:39am UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/4 "2006-09-29T06:39:05Z")

</div>

dmack wrote:

> However, when I populate a pull-down menu using collection\_select, the  
> symbol reverts back to either &pound or &euro which doesn’t look as  
> pretty ☹

Yes, the Rails select options builder is calling html\_escape on the  
option texts and values.

You’ll either have to build your html options manually, or override  
the html\_escape method.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [October 2, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/5 "2006-10-02T22:54:06Z")

</div>

Mark Reginald J. wrote:

> Yes, the Rails select options builder is calling html\_escape on the  
> option texts and values.
> 
> You’ll either have to build your html options manually, or override  
> the html\_escape method.

Aha… So collection\_select escapes html. That explains it. I will  
use your suggestion and build up the option lists manually.

Too bad we can’t pass an :escape =\> false or something to  
collection\_select.

Thank you!

Dan

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [October 6, 2006, 11:57pm UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/6 "2006-10-06T23:57:29Z")

</div>

dmack wrote:

> Aha… So collection\_select escapes html. That explains it. I will  
> use your suggestion and build up the option lists manually.
> 
> Too bad we can’t pass an :escape =\> false or something to  
> collection\_select.

Good idea. While the value tag of the option must be escaped  
(see [http://dev.rubyonrails.org/ticket/2011](http://dev.rubyonrails.org/ticket/2011)), the option text  
is html, and that need not be escaped. I’ll submit a patch.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [October 2, 2006, 10:56pm UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/7 "2006-10-02T22:56:06Z")

</div>

Mark Reginald J. wrote:

> Yes, the Rails select options builder is calling html\_escape on the  
> option texts and values.
> 
> You’ll either have to build your html options manually, or override  
> the html\_escape method.

Mark,

You are correct. I didn’t know that it did that until now but now I  
do. It’s too bad we can’t pass an :escape =\> false or something to  
collection\_select.

Thank you for you help,

Dan

---

<div class="post-metadata">

**Author:** ![dmack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dec6dc/32.png) [@dmack](https://www.ruby-forum.com/u/dmack)\
**Post date:** [October 7, 2006, 4:24pm UTC](https://www.ruby-forum.com/t/collection-select-is-quoting-my-text-method-text/70093/8 "2006-10-07T16:24:37Z")

</div>

dmack wrote:

> This table is currently loaded with these values:
> 
> currencies:
> 
> Name ch
> 
> * * *
> 
> U.S.D $  
> Euro &euro  
> G.B.P. &pound
> 
> Instead of putting the pretty html version of &pound and &euro in my  
> pull down menu, collection\_select’s form is quoting them and I still  
> see the “&pound” and “&euro” text.
> 
> Anyone have a way to work around this?
> 
> Thanks!

here, you dropped this: ‘;’

try € and £
