这里的新手。我只是想列出“站点”中的所有对象。我知道这是非常简单的事情,但我似乎无法找到它!
错误:
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 %>
我的“网站”控制器:
class SitesController < ApplicationController
def index
@sites = Site.all
end
def show
@site=Site.find(params[:id])
end
end
我的观点 - Views/home/index.html.erb
<u>SITES</u>
<br>
<% @sites.each do |site| %>
<%= site.name %>
<% end %>
还有我的 routes.rb
resources :sites
resources :critics
root :to => "home#index"