NoMethodError undefined method each


#1

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

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!


#2

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?


#3

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


#4

@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

#5

Yes, I get 'undefined local variable or method'


#6

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