1
votes

Simple task. I want to add a css class on my following f.select tag in haml. I have tried this:

.field= f.select :sponsor_id, sponsors.map { |s| [s.name, s.id] }, {:class => "my-class"}

it doesn't throw an exception but also doesn't append the class to the select element. Tried without brackets, also no success.

2

2 Answers

5
votes

I think you want

.field= f.select :sponsor_id, sponsors.map { |s| [s.name, s.id] }, {}, {:class => "my-class"}

Note the extra curlies.

Check the documentation.

1
votes

It should work if you remove it out of the brackets

.field= f.select :sponsor_id, sponsors.map { |s| [s.name, s.id] }, :class => "my-class"

or perhaps this,

.field= f.select :sponsor_id, sponsors.map { |s| [s.name, s.id] }, {}, {:class => "my-class"}