Ok, totally no reason why I’m getting an error in this model update
and no other. HELP!
@employee = Employees.find(params[:id])
<%= error_messages_for :employees %>
<% form_for(@employee) do |f| %>
||<%= f.text_field :email %> (required, will be login to
All pretty standard stuff - what’s going on?
NoMethodError in Employees#edit
Showing employees/edit.html.erb where line #5 raised:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.to_sym
Extracted source (around line #5):
3: <%= error_messages_for :employees %>
5: <% form_for(@employee
) do |f| %>
Thanks so much in advance!
Look in your controller where you assign @employee. You are calling find
plural model (Employees.find). Is your model defined as “Employees”? The
Rails convention is to have models named in a singular form, ie
because it defines an instance of a singleton object.
Try changing Employees.find to Employee.find and see if that clears up
Also, this might be way off, but some attribute names can cause problems
ActiveRecord. Attributes that have the same name as internal
methods cause sporadic errors. The Rails wiki has a running list of
pseudo-reserved words known to cause problems with AR:
Basically your var @employee is nil when you pass it to form_for().
That means Employees.find(params[:id]) is returning nil (either is not
working, or the :id doesn’t exist)…
As Patrick put, the model name is not standard (should be Employee)
and finding by hand may also help.