Search code examples
cssruby-on-railsselectsimple-formslim-lang

Adding a css class to select in Rails


I've been trying to make the following class applies on the select/dropdown, but I couldn't!

 = f.select attr, [1,2,3],  class: 'form-control', include_blank: true

I tried to read the rails code, here and here. it's like it is not implemented ? but it works for text fields:

 = f.search_field attr, options.merge(class: 'form-control')

I'm using slim and simple_form


Solution

  • select takes 2 hash options, first for 'select options' and another for 'html'.

    Try following:

    = f.select(attr, [1,2,3], { include_blank: true }, { class: 'form-control' })