This project is archived and is in readonly mode.

#5755 ✓invalid

select_tag doesn't generate options tag properly

Reported by Javix | October 4th, 2010 @ 10:30 AM

On Windows XP 64 bits, using Rails 3.0 with Ruby 1.9.2, I could not create select_tag as it is explained in the API;

<%=select_tag "count", "<option>1</option><option>2</option><option>3</option><option>4</option>"%>

the generated source code is as follows:

 <select id="count" name="count">&lt;option&gt;1&lt;/option&gt;&lt;option&gt;2&lt;/option&gt;&lt;option&gt;3&lt;/option&gt;&lt;option&gt;4&lt;/option&gt;</select>

When using the same syntax on Rails 2.3.8 and Ruby 1.8.6; everything works as needed.

Edited by Rohit Arondekar for formatting.

Comments and changes to this ticket

  • Javix

    Javix October 4th, 2010 @ 10:59 AM

    I had to add 'html_save' on option I passed:

        <%= select_tag "colors", "<option>Red</option><option>Green</option><option>Blue</option>".html_safe%>

    Would it be better to add it in the code source file actionpack/lib/action_view/helpers/form_tag_helper.rb, at lines 103 and 105 to 'option_tags' variable:

    line 103: option_tags = "<option value=\"\">#{blank}</option>".html_safe + option_tags
    line 105: option_tags = "<option value=\"\"></option>".html_safe + option_tags

    or one need to specify it always implicitly?

    Edited by Rohit Arondekar for formatting.

  • Rohit Arondekar

    Rohit Arondekar October 4th, 2010 @ 06:39 PM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

    Yes you need to mark a string as html_safe if you don't want it to be escaped. You can find more information in this excellent Railscast(ASCIIcast direct link)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>