无法以简单形式选择添加CSS类

时间:2019-06-19 07:09:23

标签: css ruby-on-rails simple-form slim-lang

我正在尝试以简单形式为select字段添加CSS,但未应用。我尝试了以下方式,

pycharm --community(2019.1)

我找到了类似的答案,但无法弄清楚。这是链接Adding a css class to select in Rails

1 个答案:

答案 0 :(得分:1)

如果您使用的是simple_form,则应使用其as: :select表示法

= f.input :user_types, as: :select,
  collection: [['Type', ''], ['College', 'admin'], ['Student', 'student']],
  input_html: { id: 'college_admin_type', class: 'form-control custom-drop-icon' }

但是,如果您使用的是默认的select帮助器,则应将html选项作为第二个选项的哈希值传递。

= f.select(:user_types, [['Type', ''], ['College', 'admin'], ['Student', 'student']], {}, { class: 'form-control custom-drop-icon' })

另请参阅Ruby on Rails form_for select field with class