Add a class to each select options with SimpleForm

大憨熊 提交于 2019-12-06 03:44:47

This appears to be a limitation when using collections, see the author of SimpleForm's explanation here. He recommends a workaround of the form:

f.input :method, :as => :select do
  f.select :method, [['option text', 'option_value_1', {"class" => "class_name_1"}], ['option text 2', 'option_value_2', {"class" => "class_name_2"}]]
end

You also can pass array of arrays as an argument

= f.input :status, collection: [['option text', 'option_value_1', {"class" => "class_name_1"}], ['option text 2', 'option_value_2', {"class" => "class_name_2"}]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!