我正在尝试在页面中插入一个simple_form下拉列表,但是在显示列表项(两个电子邮件地址[email protected]和[email protected])时遇到了麻烦。当我单击下拉列表箭头时,它们根本不会显示,因为它们不存在。
.reveal.doubt id="doubt-material-#{material.id}" data-reveal=true
button.close-button data-close=true aria-label="Close reveal" type="button"
span aria-hidden="true" ×
h5 #{t 'students.materials.index.questions.button'}
p #{t 'students.materials.index.questions.form_explanation'}
= simple_form_for [:student, trail, component, material, material_student, doubt], html: { id: "doubt" }, remote: true do |f|
= f.input :recipient, collection => %w([email protected], [email protected]), label: "#{t 'students.materials.index.questions.form_send_email'}"
= f.input :question, as: :text, label: true, label: "#{t 'students.materials.index.questions.form_message'}" , input_html: { rows: "2" }
= f.submit "#{t 'students.materials.index.questions.form_send_button'}", class: 'button primary-button-active'
当我检查代码时,它似乎可以正常工作,但是我在任何地方都看不到电子邮件选项。
我添加的代码行是:
= f.input :recipient, collection: %w([email protected], [email protected]), label: "#{t 'students.materials.index.questions.form_send_email'}"
这里怎么了?
我相信您的收藏集需要为每个选项设置name
和value
。您可以尝试:[["[email protected]", "[email protected]"], ["[email protected]", "[email protected]"]]
。或使用Rails options_for_select辅助方法:
= f.input :recipient, collection => options_for_select(%w[[email protected] [email protected]])