I can’t wrap my head around this and I could use some fresh eyes. I’m getting an undefined method in one of my views and I can’t figure out why.
I have a group of controllers under an admin namespace (i.e admin/restaurants, admin/menu). I also have a controller for admin but no model backing it. I want to use the admin index page as a dashboard to display various data from the other controllers namespaced under it. For some reason when I try to access any data from the other controllers in the admin/index view I get undefined method `each' for nil:NilClass
Routes
namespace :admin do
resources :restaurants
resources :menus
end
Controller in app/controllers/admin_controller.rb
class AdminController < ApplicationController
def Index
@restaurants = Restaurant.all
@menus = Menu.all
end
Views in app/views/admin/index.html.erb
<% @restaurants.each do |restaurant| %>
<%= restaurant.name %>
<%= restaurant.address %>
<% end %>
<% @menus.each do |menu| %>
<%= menu.name %>
<%= menu.price %>
<% end %>
def index, and notdef Index? - zeantsoi