NoMethodError undefined method each


I am getting a NoMethodError with undefined method `each' for nil:NilClass.

Here is my controls_controller.rb:

class ControlsController < ApplicationController
def index
@controls = Control.all

And here is my index.html.erb file:

<% @controls.each do |control| %>
<%=render control%>
< div class="control">
< p class="content"><%= control.content %>< /p>
< p class="time"><%= control.created_at %>< /p>
< /div>
<% end %>

Here are the routes I have configured:

get 'controls/index'
get '/controls'=>'controls#index'

Any help as to why I am getting this error would be greatly appreciated!


Hi Michcmart92,

Would you mind posting a link to the exercise you're on please, or is this for a side project not related to Codecademy?


This is related to the logic used in Ruby on Rails, Saving Data exercise #3, but doing the exercise on my own VM.


@michcmart92 OK. Can you open your terminal and tell me what you get when you type the text of these two lines (you don't type the $ or >):

$ rails console
> Controll.all


Yes, I get 'undefined local variable or method'


@michcmart92 Hm :confused: Could I see a screenshot of your terminal?