undefined method `key?' for nil:NilClass when using MongoMapper
- by Radek Slupik
I set up a new Rails application by following these instructions. I generated a new controller and added resources :tickets to the routes file.
Hexapoda::Application.routes.draw do
resources :tickets
end
This is the controller (`/app/controllers/tickets_controller.rb').
class TicketsController < ApplicationController
def index
@tickets = Ticket.all
end
end
I then added a new model Ticket in /app/models/ticket.rb.
class Ticket
include MongoMapper::Document
key :summary, String, :required => true
end
Here's the view (/app/views/index.html.erb):
<h1>Tickets#index</h1>
<p>Find me in app/views/tickets/index.html.erb</p>
Now when I go to /tickets in my browser, I get an error message.
NoMethodError in TicketsController#index
undefined method `key?' for nil:NilClass
I have no idea what's going on. What could be the problem? I'm using Rails 3.2.5 and MongoMapper 0.11.1.