我按照这些说明设置了一个新的 Rails 应用程序。我生成了一个新控制器并添加resources :tickets
到路由文件中。
Hexapoda::Application.routes.draw do
resources :tickets
end
这是控制器(`/app/controllers/tickets_controller.rb')。
class TicketsController < ApplicationController
def index
@tickets = Ticket.all
end
end
然后我Ticket
在/app/models/ticket.rb
.
class Ticket
include MongoMapper::Document
key :summary, String, :required => true
end
这是视图(/app/views/index.html.erb
):
<h1>Tickets#index</h1>
<p>Find me in app/views/tickets/index.html.erb</p>
现在,当我进入/tickets
浏览器时,我收到一条错误消息。
TicketsController#index 中的 NoMethodError
未定义的方法“键?” 对于零:NilClass
我不知道是怎么回事。可能是什么问题呢?我正在使用 Rails 3.2.5 和 MongoMapper 0.11.1。