我刚刚开始使用 Mongoid for Rails 并关注了它的截屏视频。我生成了一个脚手架,生成了 mongoid.yml,并且只更改了数据库名称。我还按照他们的文档中的步骤为 rails 准备了 mongoid。
但是,我似乎总是在创建操作中得到这个
undefined method `[]' for nil:NilClass
Rails.root: /Users/ygamayatmiretuta/Documents/Dev/ruby/ta
Application Trace | Framework Trace | Full Trace
app/controllers/notes_controller.rb:25:in `create'
这个是关于索引操作的:
undefined method `[]' for nil:NilClass
Extracted source (around line #12):
9: <th></th>
10: </tr>
11:
12: <% @notes.each do |note| %>
13: <tr>
14: <td><%= note.title %></td>
15: <td><%= note.description %></td>
我错过了配置步骤还是什么?谢谢!
这是控制器:
class NotesController < ApplicationController
respond_to :html
def index
@notes = Note.all.entries
respond_with @notes
end
def show
@notes = Note.find params[:id]
respond_with @notes
end
def new
@notes = Note.new
respond_with @notes
end
def edit
@notes = Note.find params[:id]
respond_with @notes
end
def create
@notes = Note.create params[:notes]
respond_with @notes
end
def update
@notes = Note.find params[:id]
@notes.update_attributes params[:notes]
respond_with @notes
end
def destroy
@notes = Note.find params[:id]
@notes.destroy
respond_with @notes
end
end