Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `key?' for nil:NilClass when using MongoMapper

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.


1 Answers

You need the latest MonoMapper from Master:

gem 'mongo_mapper', github: "jnunemaker/mongomapper"

And run bundle

Explanation: Rails 3.2.4 added a accessible_attributes method to ActiveModel, but MongoMapper already had this; so they were clobbering each other.

MM issue: Issue 419
MM commit that fixes: 4d35c67

like image 86
Jesse Wolgamott Avatar answered Sep 02 '25 16:09

Jesse Wolgamott