Reputation: 6389
I'm having trouble using special characters with &-notation in ruby on rails forms. Have a look:
<% form_for(@object) do |f| %>
<%= f.select :field, [['option 1', 1], [' option 1.1', 2]] %>
<% end %>
As you see, option 1.1 should have two whitespaces in the front, it should look indented in the dropdown list. Being HTML, this does not work, I should use . How do I do this in this case?
Upvotes: 0
Views: 915
Reputation: 65467
If your aim is to visually display indentation only, use CSS and set a class on the relevant options:
<%= f.select :field, [['option 1', 1], ['option 1.1', 2, { :class=>'indent_level_1' }]] %>
<style>
.indent_level_1
{
color:red; /*just for testing whether the class got applied or not.*/
margin-left:1em;
}
</style>
If
is supposed to be part of the text (I guess not?), then you can use raw():
<%= f.select :field, [['option 1', 1], [raw(' option 1.1', 2)]] %>
Ps. Proper name for "&-notation" is "HTML character entity references"
Upvotes: 1