Sunday, 15 March 2015

Rails Mongoid "undefined method `[]' for nil:NilClass" on controller index and create -



Rails Mongoid "undefined method `[]' for nil:NilClass" on controller index and create -

i have started using mongoid rails , followed screencast it. have generated scaffold, have generated mongoid.yml, , changed database name. have followed steps prepare mongoid rails in documentation.

however, seem getting on create action

undefined method `[]' nil:nilclass rails.root: /users/ygamayatmiretuta/documents/dev/ruby/ta application trace | framework trace | total trace app/controllers/notes_controller.rb:25:in `create'

and 1 on index action:

undefined method `[]' nil:nilclass extracted source (around line #12): 9: <th></th> 10: </tr> 11: 12: <% @notes.each |note| %> 13: <tr> 14: <td><%= note.title %></td> 15: <td><%= note.description %></td>

am missing config step or something? thanks!

this controller:

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

here @tasks nil. , trying iterate it. thats why error coming.

ruby-on-rails ruby-on-rails-3 mongodb mongoid

No comments:

Post a Comment