I am a bit confused as to why I am getting an error updating an object. This is the ERROR: Couldn''t find User without an ID In my development.log file I noticed the following when trying to initiate the update: Processing AdminController#update_user (for 127.0.0.1 at 2007-02-16 13:20:23) [POST] Session ID: 2a5030c37fa9726e6e29d7a024ce97ab Parameters: {"user"=>{"name"=>"joseph", "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} [4;36;1mUser Load (0.000761) [0m [0;1mSELECT * FROM users WHERE (users.id = ''11'') LIMIT 1 [0m [4;35;1mUser Columns (0.002650) [0m [0mSHOW FIELDS FROM users [0m [4;36;1mSQL (0.001330) [0m [0;1mBEGIN [0m [4;35;1mUser Load (0.000497) [0m [0mSELECT * FROM users WHERE (users.name = ''joseph'' AND users.id <> 11) LIMIT 1 [0m [4;36;1mSQL (0.000096) [0m [0;1mCOMMIT [0m Redirected to http://localhost:3000/admin/edit_user Completed in 0.01380 (72 reqs/sec) | DB: 0.00533 (38%) | 302 Found [http://localhost/admin/update_user/11] What I find most confusing is this line: SELECT * FROM users WHERE (users.name = ''joseph'' AND users.id <> 11) LIMIT 1 I am confused why Rails would make this call with update_attributes. I am lost. Any help would be greatly appreciated! Thanks, -E Here is snippets of my Admin controller code that is in question: def edit_user @user = User.find(params[:id]) end def update_user @user = User.find(params[:id]) if @user.update_attributes(params[:user]) flash[:notice] = "User #{@userUpdate.name} updated successfully" redirect_to(:action =>:list_users) else flash[:notice] = "Unable to process change, please try again" redirect_to(:action =>:edit_user) end end Here is the edit_user.rhtml file: <h1>Update User</h1> <%= start_form_tag :action => ''update_user'', :id => @user %> <%= render :partial => ''form'' %> <%= submit_tag " Update User " %> <%= end_form_tag %> <%= link_to ''Back'', :action => ''list_users'' %> Here is the _form.rhtml file: <%= error_messages_for ''user'' %> <!--[form:call]--> <table> <tr> <td>Username:</td> <td><%= text_field("user","name") %></td> </tr> <tr> <td>Password:</td> <td><%= password_field("user","hashed_password") %></td> </tr> <tr> <td>User Type:</td> <td><%= select("user","user_type", %w{nelnet wsu}) %></td> </tr> <tr> <td>User Role:</td> <td><%= select("user","user_role", %w{user super admin}) %><td> </tr> <table> <!--[eoform:call]--> Any help would be great --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/16/07, namwob <ebowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am a bit confused as to why I am getting an error updating an > object. > > This is the ERROR: Couldn''t find User without an IDbefore you start getting to the strange SQL call, try and find out why an ID isn''t being passed. At what line do you receive this error? At the User.find(params[:id]) ? If so, find out why you''re not getting a value for an id here, then try to figure out the next part. Mike --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The id does get passed. Note from my dev.log file the parameters getting passed: Parameters: {"user"=>{"name"=>"joseph", "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} id is listed, so it makes it to the controller. On Feb 16, 2:01 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am a bit confused as to why I am getting an error updating an > > object. > > > This is the ERROR: Couldn''t find User without an ID > > before you start getting to the strange SQL call, try and find out why > an ID isn''t being passed. At what line do you receive this error? At > the User.find(params[:id]) ? If so, find out why you''re not getting a > value for an id here, then try to figure out the next part. > > Mike--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
what exact line is causing rails to throw that error? On 2/16/07, namwob <ebowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The id does get passed. Note from my dev.log file the parameters > getting passed: > > Parameters: {"user"=>{"name"=>"joseph", > "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", > "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User > ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} > > id is listed, so it makes it to the controller. > > On Feb 16, 2:01 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I am a bit confused as to why I am getting an error updating an > > > object. > > > > > This is the ERROR: Couldn''t find User without an ID > > > > before you start getting to the strange SQL call, try and find out why > > an ID isn''t being passed. At what line do you receive this error? At > > the User.find(params[:id]) ? If so, find out why you''re not getting a > > value for an id here, then try to figure out the next part. > > > > Mike > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here is the application TRACE: /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/ base.rb:939:in `find_from_ids'' /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/ base.rb:382:in `find'' #{RAILS_ROOT}/app/controllers/admin_controller.rb:45:in `edit_user'' /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ i386/bin/mongrel_rails:18 On Feb 16, 2:06 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what exact line is causing rails to throw that error? > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > The id does get passed. Note from my dev.log file the parameters > > getting passed: > > > Parameters: {"user"=>{"name"=>"joseph", > > "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", > > "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User > > ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} > > > id is listed, so it makes it to the controller. > > > On Feb 16, 2:01 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am a bit confused as to why I am getting an error updating an > > > > object. > > > > > This is the ERROR: Couldn''t find User without an ID > > > > before you start getting to the strange SQL call, try and find out why > > > an ID isn''t being passed. At what line do you receive this error? At > > > the User.find(params[:id]) ? If so, find out why you''re not getting a > > > value for an id here, then try to figure out the next part. > > > > Mike--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The issue that I can''t grasp is why this call was made in my log file for a simple update call SELECT * FROM users WHERE (users.name = ''joseph'' AND users.id <> 11) On Feb 16, 2:06 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what exact line is causing rails to throw that error? > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > The id does get passed. Note from my dev.log file the parameters > > getting passed: > > > Parameters: {"user"=>{"name"=>"joseph", > > "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", > > "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User > > ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} > > > id is listed, so it makes it to the controller. > > > On Feb 16, 2:01 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am a bit confused as to why I am getting an error updating an > > > > object. > > > > > This is the ERROR: Couldn''t find User without an ID > > > > before you start getting to the strange SQL call, try and find out why > > > an ID isn''t being passed. At what line do you receive this error? At > > > the User.find(params[:id]) ? If so, find out why you''re not getting a > > > value for an id here, then try to figure out the next part. > > > > Mike--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can someone explain why "validates_presence_of" screws up a call to update a model object? On Feb 16, 2:11 pm, "namwob" <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The issue that I can''t grasp is why this call was made in my log file > for a simple update call > > SELECT * FROM users WHERE > (users.name = ''joseph'' AND users.id <> 11) > > On Feb 16, 2:06 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > what exact line is causing rails to throw that error? > > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > The id does get passed. Note from my dev.log file the parameters > > > getting passed: > > > > Parameters: {"user"=>{"name"=>"joseph", > > > "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", > > > "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User > > > ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} > > > > id is listed, so it makes it to the controller. > > > > On Feb 16, 2:01 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I am a bit confused as to why I am getting an error updating an > > > > > object. > > > > > > This is the ERROR: Couldn''t find User without an ID > > > > > before you start getting to the strange SQL call, try and find out why > > > > an ID isn''t being passed. At what line do you receive this error? At > > > > the User.find(params[:id]) ? If so, find out why you''re not getting a > > > > value for an id here, then try to figure out the next part. > > > > > Mike--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
what you''re doing looks fine, and the database query is definitely strange, but somewhere along the line, rails is executing a find without an ID. The application trace doesn''t show what line in your code is causing the error. Using validates_presence_of shouldn''t have any side effect, unless you''re modifying it with an "if" condition and introducing an error at that point. Mike On 2/16/07, namwob <ebowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Can someone explain why "validates_presence_of" screws up a call to > update a model object? > > On Feb 16, 2:11 pm, "namwob" <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > The issue that I can''t grasp is why this call was made in my log file > > for a simple update call > > > > SELECT * FROM users WHERE > > (users.name = ''joseph'' AND users.id <> 11) > > > > On Feb 16, 2:06 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > what exact line is causing rails to throw that error? > > > > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > The id does get passed. Note from my dev.log file the parameters > > > > getting passed: > > > > > > Parameters: {"user"=>{"name"=>"joseph", > > > > "hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352", > > > > "user_type"=>"nelnet", "user_role"=>"user"}, "commit"=>" Update User > > > > ", "action"=>"update_user", "id"=>"11", "controller"=>"admin"} > > > > > > id is listed, so it makes it to the controller. > > > > > > On Feb 16, 2:01 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 2/16/07, namwob <ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > I am a bit confused as to why I am getting an error updating an > > > > > > object. > > > > > > > > This is the ERROR: Couldn''t find User without an ID > > > > > > > before you start getting to the strange SQL call, try and find out why > > > > > an ID isn''t being passed. At what line do you receive this error? At > > > > > the User.find(params[:id]) ? If so, find out why you''re not getting a > > > > > value for an id here, then try to figure out the next part. > > > > > > > Mike > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---