渲染页面时,为什么下拉列表项不会显示在我的simple_form_for集合代码中?

我试图在页面中插入一个simple_form下拉列表,但是在显示列表项时遇到麻烦(两个电子邮件地址-conatct@test.com和support@test.com)。当我单击下拉列表箭头时,它们根本不会显示,因为它们不存在。

.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(contact@test.com,support@test.com),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(contact@test.com,label: "#{t 'students.materials.index.questions.form_send_email'}"

这是怎么了?

lost32 回答:渲染页面时,为什么下拉列表项不会显示在我的simple_form_for集合代码中?

我相信您的收藏集需要为每个选项设置namevalue。您可以尝试:[["contact@test.com","contact@test.com"],["support@test.com","support@test.com"]]。或使用Rails options_for_select辅助方法:

= f.input :recipient,collection => options_for_select(%w[contact@test.com contact@test.com])
本文链接:https://www.f2er.com/3157938.html

大家都在问