2013-02-14 73 views
0

我剛剛開始使用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 
+0

什麼是你遵循的步驟? 你能發佈完整跟蹤嗎? – 2013-02-14 11:19:38

回答

0

我已更新到Ruby 1.9.3並解決了這些問題。

+0

我的猜測是因爲您沒有'不接受答案。我已經給你upvote,希望你接受它:) – 2013-06-08 00:30:03

0

這裏@tasks爲零。你正試圖迭代它。這就是爲什麼這個錯誤即將到來。

+0

它顯然是零但是是什麼原因導致它是如此?我的意思是,我已經遵循了這些步驟,但是,我無法創建記錄,因爲它在我的控制檯中嘗試了N'Class''ndefined method []方法[]' – yretuta 2013-02-14 08:21:25

+0

粘貼您的控制器.. – vijikumar 2013-02-14 08:25:08

相關問題