我在= select_tag :ethnicity, ['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other'], prompt: 'ethnicity/race'
no implicit conversion of Array into String
收到错误消息
有人可以协助吗?
index.html.slim:
= form_tag searches_path, method: :get do
.select4
.col.col7 style='margin-left: 10px;width:233px;'
= select_tag :ethnicity, ['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other'], prompt: 'ethnicity/race'
答案 0 :(得分:2)
试试这个
= select_tag :ethnicity, options_for_select(['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other'])
请注意options_for_select
方法
答案 1 :(得分:2)
select_tag(name, option_tags = nil, options = {}) public
Helpers :: FormOptions可用于创建常用选择框,例如国家/地区,时区,>或相关记录。 option_tags 是一个包含选择框选项标签的字符串。
http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag
第二个参数应该是HTML字符串 - 而不是数组。您可以使用options_for_select
从数组生成选项标记。