NameError (uninitialized constant *nameofcontroller* error in Rails
I am new to RoR and trying simple CRUD operations withou开发者_开发问答t scafolding. I have a model called ccword, with controller named WordsController.
Problem is I am creating simple 'create' and leading me to this error: NameError in C cwordsController#create
uninitialized constant CCwordsController
This is how my create method in my controller looks like:
def create
@ccword = CCword.new(params[:ccword])
respond_to do |format|
if @ccword.save
flash[:notice] = 'Word was successfully added.'
format.html { redirect_to(@ccword) }
format.xml { render :xml => @ccword, :status => :created, :location => @ccword }
else
flash[:notice] = 'Error.'
format.html { render :action => "show" }
format.xml { render :xml => @ccword.errors, :status => :unprocessable_entity }
end
end
end
end
my view new.html.erb looks like :
<h1>Words new</h1>
<% form_for (@ccword) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :word %><br />
<%= f.text_field :word %>
</p>
<p>
<%= f.label :meaning %><br />
<%= f.text_field :meaning %>
</p>
<p>
<%= f.submit 'create' %>
</p>
<% end %>
When I click create I get above NameError. In console following log gets displayed:
Processing ApplicationController#create (for 127.0.0.1 at 2009-11-19 09:33:06) [POST]
Parameters: {
"commit"=>"Create",
"authenticity_token"=>"hqf54HkXSaTPGejGSbEPcw3ZpOy1Ayp3gvti29gc7Eg=",
"c_cword"=>{"meaning"=>"2", "word"=>"2"}
}
NameError (uninitialized constant CCwordsController):
Any idea?
The problem is here:
format.html { redirect_to(@ccword) }
try changing it to
format.html { redirect_to word_path(@ccword) }
精彩评论