我剛剛開始使用Mongoid for Rails,並對其進行了截屏。我生成了一個腳手架,生成了mongoid.yml,並且只更改了數據庫名稱。我也遵循了在他們的文檔中準備mongoid for rails的步驟。Rails Mongoid「undefined method`[]'for nil:NilClass」on controller index and create
但是,我似乎總是在創建行動
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
什麼是你遵循的步驟? 你能發佈完整跟蹤嗎? – 2013-02-14 11:19:38