Why am I getting an undefined method `each' for nil:NilClass?
Total neophyte here. I'm just trying to list all of the objects in
'sites'. I know it's something agonizingly simple, but I just can't seem
to track it down!
The error:
NoMethodError in Home#index
Showing
/Users/jasonmurphy/data/projects/moviefeed/app/views/home/index.html.erb
where line #6 raised:
undefined method `each' for nil:NilClass
Extracted source (around line #6):
3: <u>SITES</u>
4: <br>
5:
6: <% @sites.each do |site| %>
7: <%= site.name %>
8: <% end %>
My 'sites' controller:
class SitesController < ApplicationController
def index
@sites = Site.all
end
def show
@site=Site.find(params[:id])
end
end
My view - Views/home/index.html.erb
<u>SITES</u>
<br>
<% @sites.each do |site| %>
<%= site.name %>
<% end %>
And my routes.rb
resources :sites
resources :critics
root :to => "home#index"
No comments:
Post a Comment