anmaree
anmaree

Reputation: 657

can't convert Symbol into Integer model error

I am getting this error that I have never seen before

can't convert Symbol into Integer

model:

@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>

Upvotes: 0

Views: 235

Answers (2)

marknach
marknach

Reputation: 232

@customers is being declared as an array, which is indexed by integer, but you are passing in a symbol.

If you're looking to find a customer by :group_name

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

Upvotes: 0

usha
usha

Reputation: 29369

@customers is an array

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

Upvotes: 2

Related Questions