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 Thanks in advance! -jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Dec-15 10:29 UTC
Re: nil.update_attributes on variable from find_by...
On Dec 15, 8:39 am, John Edward <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> > 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) > > FredThe 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Either use a ruby-debug gem and debug your code or do a puts @the_factor in your code and check the development log file. The variable @the_factor is nil, the error message has nothing to do with update_attributes. On Dec 15, 2007 9:12 AM, John Edward <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Frederick Cheung wrote: > > > > 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! > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---