Hi there, I''m running my app using rails 2.0.2. When running the create method in my controller, I get the following error: ---------------------------------- 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.[] app/controllers/routes_controller.rb:39:in `create'' Parameters: {"commit"=>"Create", "route"=>{"name"=>"testroute"}, "user_ids"=>["1", "4"], "heading_id"=>"0" --------------------------------- Here''s line 39 in the controller: @route.users = User.find(@params[:user_ids]) if @params[:user_ids] I don''t understand what''s going on here. The following works when I run it in the console: User.find([1,4]) I''m at a loss as to why this doesn''t work. Can anyone help me here? 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 -~----------~----~----~----~------~----~------~--~---
On Jun 30, 2008, at 9:24 PM, Jason Floyd wrote:> > Hi there, > > I''m running my app using rails 2.0.2. > > When running the create method in my controller, I get the following > error: > > ---------------------------------- > 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.[] > > app/controllers/routes_controller.rb:39:in `create'' > > Parameters: > > {"commit"=>"Create", > "route"=>{"name"=>"testroute"}, > "user_ids"=>["1", > "4"], > "heading_id"=>"0" > > --------------------------------- > > Here''s line 39 in the controller: > > @route.users = User.find(@params[:user_ids]) if @params[:user_ids]Should be @route.users = User.find(params[:user_ids]) if params[:user_ids] The current code is trying to use an instance variable name params Best. Mike> > > I don''t understand what''s going on here. The following works when I > run > it in the console: > > User.find([1,4]) > > I''m at a loss as to why this doesn''t work. > > Can anyone help me here? > > 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 -~----------~----~----~----~------~----~------~--~---
> Should be @route.users = User.find(params[:user_ids]) if > params[:user_ids]Well, that fixed it. The previous code I had did work, maybe when I upgraded to rails 2.0 it stopped? This method doesn''t get run much and could have gone unnoticed. Thanks so much for your help. Jason -- 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 -~----------~----~----~----~------~----~------~--~---
You''re welcome Jason. You can check out this post for more detail on @params vs. params http://weblog.rubyonrails.org/2006/4/25/use-params-not-params Best. Mike On Jun 30, 2008, at 9:51 PM, Jason Floyd wrote:> >> Should be @route.users = User.find(params[:user_ids]) if >> params[:user_ids] > > Well, that fixed it. The previous code I had did work, maybe when I > upgraded to rails 2.0 it stopped? This method doesn''t get run much > and > could have gone unnoticed. > > Thanks so much for your help. > > Jason > -- > 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 -~----------~----~----~----~------~----~------~--~---