TypeError:没有将Array隐式转换为String

时间:2014-11-18 23:43:53

标签: ruby-on-rails forms

我在= 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'

2 个答案:

答案 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方法

Source

答案 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从数组生成选项标记。