0

Mongoid for Rails の使用を開始したばかりで、スクリーンキャストに従いました。scaffold を生成し、mongoid.yml を生成し、データベース名のみを変更しました。また、ドキュメンテーションでレール用にモンゴイドを準備する手順に従いました。

ただし、作成アクションで常にこれを取得しているようです

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'

そして、これは index アクションで:

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
4

3 に答える 3

0

Ruby1.9.3にアップグレードする必要があります。以下を参照してください。

https://github.com/mongoid/mongoid/issues/2194

于 2013-02-24T19:12:11.943 に答える
0

ここで@tasksはnilです。そして、あなたはそれを繰り返そうとしています。そのため、このエラーが発生します。

于 2013-02-14T08:19:45.087 に答える
0

Ruby 1.9.3 に更新すると、問題が修正されました。

于 2013-02-15T06:10:21.363 に答える