无法将符号转换为整数模型错误

时间:2013-12-17 18:37:56

标签: ruby-on-rails

我收到了此前我从未见过的错误

无法将符号转换为整数

模型:

@customers = [
    {
        :customer_name => 'James',
        :group_name => 'Latin@ Social Work Coalition',
    }

html.erb

<div id="group_name" class="group-name">
  <h1>
    <%= @customers[:group_name] %>
  </h1>
</div>

2 个答案:

答案 0 :(得分:2)

@customers是一个数组

<div id="group_name" class="group-name">
  <h1>
    <%= @customers.first[:group_name] %> #or @customers[0][:group_name]
  </h1>
</div>

答案 1 :(得分:0)

@customers被声明为一个数组,它由整数索引,但是你传入一个符号。

如果您希望通过以下方式找到客户:group_name

<%= @customers.detect { |customer| customer[:group_name] == <GROUP_WANTED> } %>
相关问题