CombatCaptain CombatCaptain - 2 months ago 9
Ruby Question

undefined method `resources' for nil:NilClass

I am learning Ruby on Rails and trying to create a sample app. I have created the following files:

app/controllers/books_controller.rb

class BooksController < ApplicationController
def index
@books = Book.all
end
end


app/models/book.rb

class Book < ApplicationRecord
end


config/routes.rb

Rails.application.routes.draw do |map|
map.resources :books
end


I am using ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
and rails 5.0.0.1 versions.

Why I am getting error undefined method 'resources' for nil:NilClass?

Answer
Rails.application.routes.draw do
    resources :books
end
Comments