Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Migrations and Relationships Has and Belongs to Many

Rails views displaying SQL result array

I'm in the process of creating the views for the index and the show pages. I believe the code is exactly as displayed in the video but I may have missed something. When I view the pages, the server appears to be inserting the SQL result array and I cannot figure out why.

For instance, my index page displays:

[#<Customer id: 1, type: "Customer", name: "Bob's Emporium", email: nil, about: nil, created_at: "2015-07-24 15:34:39", updated_at: "2015-07-24 15:37:32">, #<Employee id: 2, type: "Employee", name: "Hampton", email: "hcatlin@gmail.com", about: nil, created_at: "2015-07-24 15:34:39", updated_at: "2015-07-24 15:38:18">]
Bob's Emporium  Customer
Hampton     Employee

the result array is above the table element so I have no idea why it is being inserted there.

My controller code:

class AccountsController < ApplicationController
     def index
          @accounts = Account.all
     end

     def show
          @account = Account.find(params[:id])
     end
end

My index view code:

<table>
     <%= @accounts.each do | account | %>
     <tr>
          <td><%= link_to account.name, account_path(account) %></td>
          <td><%= account.type.to_s %></td>
     </tr>
     <% end %>
</table>

1 Answer

I want to give you the satisfaction of solving this one.

Edit: I've had to edit this like three times because apparently treehouse doesn't escape their text inputs.

<table>
    # There is a difference between `<%=` and `<%`.

     <%= @accounts.each do | account | %>
     <tr>
          <td><%= link_to account.name, account_path(account) %></td>
          <td><%= account.type.to_s %></td>
     </tr>
     <% end %>
</table>

I swear it's always 1 character! Thanks for catching that.