Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

select_tag doesn't generate options tag properly

#5755

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.

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Javix
    Javix

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

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

    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.

    October 4th, 2010 @ 10:59 AM

  2. Rohit Arondekar
    Rohit Arondekar
    • 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)

    October 4th, 2010 @ 06:39 PM