简体   繁体   English

TypeError:数组未隐式转换为String

[英]TypeError: no implicit conversion of Array into String

I am receiving a error on the line = select_tag :ethnicity, ['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other'], prompt: 'ethnicity/race' that reads no implicit conversion of Array into String 我在线= select_tag :ethnicity, ['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other'], prompt: 'ethnicity/race'收到错误= 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读取no implicit conversion of Array into String

Can someone assist? 有人可以协助吗?

index.html.slim: 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'

Try this 尝试这个

= select_tag :ethnicity, options_for_select(['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other'])

Note the options_for_select method 注意options_for_select方法

Source 资源

select_tag(name, option_tags = nil, options = {}) public

Helpers::FormOptions can be used to create common select boxes such as countries, time zones, > or associated records. Helpers :: FormOptions可用于创建常见的选择框,例如国家/地区,时区,>或相关记录。 option_tags is a string containing the option tags for the select box. option_tags是一个字符串,其中包含选择框的选项标签。

http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag

The second parameter should be a HTML string - not an array. 第二个参数应该是HTML字符串-而不是数组。 You can use options_for_select to generate option tags from an array. 您可以使用options_for_select从数组生成选项标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM