Reputation: 319
I'm trying to hardcode a simple html select_tag but my option values are not rendering. I have a student table and want them to select a class group: Freshman, Sophomore, Junior, Senior. Here is my code in form.html.erb that I tried with just Freshman:
Class Year <%= select_tag "class", "<option>Freshman</option>" %>
Any suggestions? Thanks
Upvotes: 0
Views: 1346
Reputation: 18218
The option part was getting sanitized by rails 3. It seems like rails 2 didn't do this, so you were probably looking at documentation written for an older version of rails. This is how I got the options tag to render with your example
<%= select_tag "class", raw("<option>Freshman</option>") %>
Be careful about using this arbitrarily. raw
tells rails to leave any string as it is when rendering HTML. If you're rendering dynamic content that users can modify (not the case here), you'll be vulnerable to SQL injection attacks.
Btw, the way I figured out what was amiss here was by using firebug (Firefox plugin) and viewing the rendered page. You can right click on page elements and inspect element
to see the html. You can also do this with any browser's "view source" but I find this just a tad more convenient. This is what the html looked like with your original code:
<select id="class" name="class"><option>Freshman</option></select>
Upvotes: 2