Simple array problem

Hello - I am trying to create a simple array with my todos_controller.rb and index.html.erb files.
Here is what i have in my controller:

class TodosController < ApplicationController
  def index
     @todo_array = [ "Buy Milk", "Buy Soap", "Draw Money" ]

Here is what i have in my Index file:

<title>Shared Todo App </title>
   <h1>Shared Todo App</h1>
<p>All your todos here</p>
<% @todo_array.each do |t| %>
<li> <%= puts t %> </li>
<% end %>

When i start up the server to view the page the array is not being displayed correctly. Can someone point me in the right direction?

What’s your error message?

puts returns nil. You can open an irb console and type

puts “A”

It will print A and then it will return nil

In your code you are doing:

  • <%= puts t %>
  • So you get a lot of nils and print them in the stdout.

    Try doing:

  • <%= t %>
  • When printing things for “debugging purposes” you can better use p

    In an irb session try:

    p “A”

    It will print A and return A.

    Fixed my problem … Thank you

    It was not outputting any results.