I have a pre-populated Factor row that belongs to a Job (Job has one
Factor). The upd_factor form looks fine – brings in all expected
Factor data for that Job, but when I hit submit after making changes, it
throws the error at the end of this message.
def upd_factor @the_factor = Factor.find_by_job_id(params[:job_id])
if request.post? @the_factor.update_attributes(params[:the_factor])
redirect_to :action => ‘index’, :job_id => 22
end
end
(I commented out the one line to put focus on the update_attributes
line…) seems like what i’m trying to do is simple enough – any ideas
on what i’m missing?
MESSAGE:
You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.update_attributes
I have a pre-populated Factor row that belongs to a Job (Job has one
Factor). The upd_factor form looks fine – brings in all expected
Factor data for that Job, but when I hit submit after making changes, it
throws the error at the end of this message.
def upd_factor @the_factor = Factor.find_by_job_id(params[:job_id])
if request.post? @the_factor.update_attributes(params[:the_factor])
What is params[:job_id]. Is it what you think it is (the fact that
find_by_job_id is returning nil suggests that it isn’t)
What is params[:job_id]. Is it what you think it is (the fact that
find_by_job_id is returning nil suggests that it isn’t)
Fred
The Factor form is populated as i expect it to w/ the find_by_id line
(and if I take that line out it breaks), so I expect that
params[:job_id] is working – it’s the update_attributes line that is
killing me.
Earlier, before I added the concept of Job to the program (and therefore
had only one Factor and no need to find the correct Factor for the form)
it worked as expected. Now I have to use the find_by_job_id to get the
correct Factor, and the update_attributes blows up.
Sorry, that was a little wordy – hopefully I’m making sense…
Thanks!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.