Undefined local variable or method

This is probably something pretty simple, but I’m new to Rails, so I’m
stumped.

I am trying to implement an “edit” form on a simple rails application,
so that users can update a record that already exists.

Here is my “edit” form:

-------app/views/words/edit.html/erb----------

Edit Word

<% form_for @word, :url => { :action => “update” } do |f| %>

  • Word: <%= f.text_field :spelling %>
  • Modern Spelling: <%= text_field(:modword, :modspell) %>
  • Part of Speech: <%= f.text_field :speechpart %>
  • Form: <%= f.text_field :form %>
  • Meaning: <%= f.text_field :meaning %>
  • Text Source: <%= f.text_field :textsource %>
  • Definition Source: <%= f.text_field :defsource %>

<%= submit_tag "Update"%> <% end %> ----------------------------------------------

And here is my controller:
----------app/controllers/words_controller.rb-----------
class WordsController < ApplicationController
def index
@words = Word.find(:all)
end
def show
@word = Word.find(params[:id])
end
def new
@word = Word.new
end
def create
@modword = (Modword.find_by_modspell(params[:modword][:modspell])
|| Modword.create(params[:modword]))
@word = Word.new(params[:word].merge(:modword_id => @modword.id))
if @word.save
redirect_to(:action => :index)
else
render :action => ‘new’
end
end
def edit
@word = Word.find(params[:id])
@modword = Modword.find(@word.modword_id)
end
def update
@word = word.find(params[:id])
@modword = (Modword.find_by_modspell(params[:modword][:modspell])
|| Modword.create(params[:modword]))
if @word.update_attributes(params[:word])
redirect_to :action => ‘show’, :id => @word
else
render :action => ‘edit’
end
end
def delete
Word.find(params[:id]).destroy
redirect_to :action => ‘list’
end
end

When I use the “edit” form, I get the following error:

NameError in WordsController#update

undefined local variable or method `word’ for
#WordsController:0x2fddd40

app/controllers/words_controller.rb:25:in `update’

Does anyone have any idea what’s going on here? I can’t find the
problem… If you need more information about my application, I’ll be
happy to provide it. Thanks in advance for your help!!

On 5 Aug 2008, at 22:26, Morgan K. wrote:

def update
@word = word.find(params[:id])

That should be Word, not word (like in all your other actions)

Fred

Frederick C. wrote:

On 5 Aug 2008, at 22:26, Morgan K. wrote:

def update
@word = word.find(params[:id])

That should be Word, not word (like in all your other actions)

Fred

Wow, I knew it was going to be something simple. The fact that I’m
missing obvious things like that probably means it’s time to take a
break…

Thanks for your help!
Morgan.

your delete action should also be called “destroy”