Search code examples
ruby-on-railsslim-lang

Slim ignoring class & style on f.select field?


I'm sure I'm being blind, can you spot something I've missed:

= f.select :region, options_for_select(YAML.load_file("#{Rails.root}/config/regions.yml").collect{|x| [x[1]['name'], x[0]]}), class: "form-control", style: 'display:none;'

Slim just ignores the class & style statements, but everything else looks fine. What am I doing wrong? (rails 4).


Solution

  • select(object, method, choices = nil, options = {}, html_options = {}, &block) public

    If you look into your code,

    = f.select :region, options_for_select(YAML.load_file("#{Rails.root}/config/regions.yml").collect{|x| [x[1]['name'], x[0]]}), class: "form-control", style: 'display:none;'
    

    class and style should be in a place of html_options = {} but currently they are in options = {}, so they are discarded.

    The below works

    = f.select :region, options_for_select(YAML.load_file("#{Rails.root}/config/regions.yml").collect{|x‌​| [x[1]['name'], x[0]]}), {}, {class: "form-control", style: 'display:none;'}