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