Dale Cunnigham
2008-Jun-12 11:43 UTC
Weird update problem.. ID value being dropped any ideas why?
Ive been trying to get my forst rials program to update and delete records ina mysql database and I''ve been experiencing this weird problem where no errors are thrown up the data doent get updated/deleted. Ive rtaced the problem down to the fact that the ID for the record to be updated or deleted is not being passed properly. But theer doesnt seem to be any way of making ti work correctly. EG: from logfile Processing UsersController#update (for 134.225.101.126 at 2008-06-12 12:15:42) [PUT] Session ID: BAh7BzoMY3NyZl9pZCIlODNmNzY3YWRhMzQ5MWU3YjY5YmYyZDM5MTU4Nzc0%0ANzkiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--67019028005bd54bb3a0ff18a2c6acfb4ad8941b Parameters: {"user"=>{"Staff"=>"1", "MscInfo"=>"0", "HdrForum"=>"0", "Internal_Sort"=>"", "Lab"=>"0", "Secs"=>"0", "UgBoard"=>"0", "Personal_Web"=>"~arrdvariusmaximus", "UgVis"=>"0", "ProbationDate"=>"", "LineManager"=>"", "BscInfo"=>"0", "PhdSuper"=>"1", "Security"=>"0", "SurName"=>"Aaardvark123", "HdrBoard"=>"0", "Research"=>"1", "Title"=>"Mr", "EMail"=>"a.aardvark-3EW9midWFo1BDgjK7y7TUQ@public.gmane.org", "ForeName"=>"Aaalan", "Year"=>"", "Cracks"=>"0", "InfoSec"=>"0", "RetirementDate"=>"", "PhoneNo"=>"1111", "Mats"=>"0", "Media"=>"1", "PhdInfo"=>"0", "ResearchGroup"=>"", "Position_Group"=>"Ardvar Asimilation", "Duties"=>"Arythmia", "Group_Web"=>"~ard", "Course"=>"", "Teapot"=>"0", "StartDate"=>"", "EndDate"=>"", "FundingBody"=>"", "ImageName"=>"noimage.gif", "RoomNo"=>"A102", "PayCategory"=>""}, "commit"=>"Update", "authenticity_token"=>"428c0c3d4d97925d4b6de702b6b65a30b58963b2", "_method"=>"put", "action"=>"update", "id"=>"1223", "controller"=>"users"} [4;36;1mUser Columns (0.013565) [0m [0;1mSHOW FIELDS FROM `users` [0m [4;35;1mUser Load (0.011418) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = ''1223'') [0m [4;36;1mSQL (0.000467) [0m [0;1mBEGIN [0m [4;35;1mUser Update (0.000980) [0m [0mUPDATE `users` SET `UgVis` 0, `LineManager` = '''', `Staff` = 1, `Position_Group` = ''Ardvar Asimilation'', `Group_Web` = ''~ard'', `Duties` = ''Arythmia'', `Title` ''Mr'', `UgBoard` = 0, `Secs` = 0, `Year` = '''', `RetirementDate` = '''', `MscInfo` = 0, `PayCategory` = '''', `ImageName` = ''noimage.gif'', `Security` = 0, `BscInfo` = 0, `Personal_Web` = ''~arrdvariusmaximus'', `Internal_Sort` = '''', `Teapot` = 0, `FundingBody` = '''', `EndDate` = '''', `SurName` = ''Aaardvark123'', `Research` = 1, `ResearchGroup` = '''', `PhoneNo` = ''1111'', `PhdInfo` = 0, `Media` = 1, `Mats` = 0, `PhdSuper` 1, `InfoSec` = 0, `ForeName` = ''Aaalan'', `Cracks` = 0, `ProbationDate` '''', `RoomNo` = ''A102'', `EMail` = ''a.aardvark-3EW9midWFo1BDgjK7y7TUQ@public.gmane.org'', `Lab` = 0, `StartDate` = '''', `Course` = '''', `ID` = 1223, `HdrBoard` = 0, `HdrForum` = 0 WHERE `id` = NULL [0m [4;36;1mSQL (0.000295) [0m [0;1mCOMMIT [0m Redirected to http://website/users/users/ Completed in 0.09493 (10 reqs/sec) | DB: 0.02672 (28%) | 302 Found [http://website/users/users/1223] As you can see in the first instance of generated SQL the ID is preserved SELECT * FROM `users` WHERE (`users`.`id` = ''1223'' but in the actual UPDATE line its getting WHERE `id` = NULL Any ideas why this might be happening? I''m using MySQL on Apache with fastcgi -- 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 -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Jun-12 12:30 UTC
Re: Weird update problem.. ID value being dropped any ideas
What''ll really help people diagnose your issue is to see the controller code... it''s a little tough to diagnose from just the output. Given the log, you have the ID, but then lose it. Maybe you''re not using an instance variable where you ought to? -- 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 -~----------~----~----~----~------~----~------~--~---
Dale Cunnigham
2008-Jun-12 13:50 UTC
Re: Weird update problem.. ID value being dropped any ideas
Ar Chron wrote:> What''ll really help people diagnose your issue is to see the controller > code... it''s a little tough to diagnose from just the output. > > Given the log, you have the ID, but then lose it. Maybe you''re not > using an instance variable where you ought to?ok here you go. class UsersController < ApplicationController # GET /users # GET /users.xml def index if params[:usersearch].blank? @users = User.find(:all, :order => ''SurName, ForeName'') else @users = User.find(:all, :order => ''SurName, ForeName'', :conditions => [''Surname LIKE ? or Forename LIKE ? or Position_Group LIKE ?'', "%#{params[:usersearch]}%", "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"]) end respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end # GET /users/1 # GET /users/1.xml def show @user = User.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @user } end end # GET /users/new # GET /users/new.xml def new @user = User.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @user } end end # GET /users/1/edit def edit @user = User.find(params[:id]) end # POST /users # POST /users.xml def create @user = User.new(params[:user]) respond_to do |format| if @user.save flash[:notice] = ''User was successfully created.'' format.html { redirect_to(@user) } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end # PUT /users/1 # PUT /users/1.xml def update @user = User.find(params[:id]) respond_to do |format| if @user.update_attributes(params[:user]) flash[:notice] = ''User was successfully updated.'' format.html { redirect_to(@user) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end # DELETE /users/1 # DELETE /users/1.xml def destroy @user = User.find(params[:id]) @user.destroy respond_to do |format| format.html { redirect_to(users_url) } format.xml { head :ok } end end end -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jun-12 14:13 UTC
Re: Weird update problem.. ID value being dropped any ideas
The update code looks simple enough, not much that can go wrong I think. One thing I see is that the id field is sometimes called ID, sometimes id. All the other fieldnames are casesensitive, too. There may(!) be a source for confusion, depending on the db you use, since the uppercase id in the update still has the correct value, while it checks for the uppercase ID, which is NULL. Otherwise any before_save filters or validations may be responsible. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dale Cunnigham
2008-Jun-12 14:57 UTC
Re: Weird update problem.. ID value being dropped any ideas
Thorsten Mueller wrote:> The update code looks simple enough, not much that can go wrong I > think. > > One thing I see is that the id field is sometimes called ID, sometimes > id. > All the other fieldnames are casesensitive, too. > There may(!) be a source for confusion, depending on the db you use, > since the uppercase id in the update still has the correct value, > while it > checks for the uppercase ID, which is NULL.Ive tried using all lower case "id" but if i use <td><%= link_to ''Edit'', edit_user_path(user.id) %></td> instead of <td><%= link_to ''Edit'', edit_user_path(user.ID) %></td> The path renders incorrectly. EG: website/users/users//edit/ instead of website/users/users/id/edit/> Otherwise any before_save filters or validations may be responsible.I don''t have any filters set or validations in the model file at this point so it can be that. This problem is really vexing me since the code looks like it should work, but even default scaffold code wont do updates or deletes but will happily create new records. -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jun-12 15:21 UTC
Re: Weird update problem.. ID value being dropped any ideas
ok, I''m running out of ideas. The controller is simple enough, that must work... How does your db look? What type is it? Oracle, MySQL? Some are case sensitive (Oracle), others not. Is there a chance, you can change the name of the id column to lowercase? At least to test it and see, what happens. This `ID` = 1223 is strange enough by itself, Rails should not try to update that col and a short glance in the output of my devlog shows, that it normally does not. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dale Cunnigham
2008-Jun-12 15:29 UTC
Re: Weird update problem.. ID value being dropped any ideas
> Is there a chance, you can change the name of the id column to > lowercase? > At least to test it and see, what happens.Well isn''t that weird, I changed ID to id using navicat (its a MySQL database) and update now works (after changing all the user.ID references to user.id). thanks a lot for kicking me in the brain. Cheers and +1 for your help. -- 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 -~----------~----~----~----~------~----~------~--~---
Dale Cunnigham
2008-Jun-12 15:38 UTC
Re: Weird update problem.. ID value being dropped any ideas
Although delete still doesn''t work. It seems to route to the show page instead of deleting and doing a redirect to the index. -- 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 -~----------~----~----~----~------~----~------~--~---
Dale Cunnigham
2008-Jun-12 15:46 UTC
Re: Weird update problem.. ID value being dropped any ideas
Dale Cunnigham wrote:> Although delete still doesn''t work. It seems to route to the show page > instead of deleting and doing a redirect to the index.Turns out that was because I was using html => {:method => :delete} instead of just :method => :delete -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jun-12 15:50 UTC
Re: Weird update problem.. ID value being dropped any ideas
On Jun 12, 5:38 pm, Dale Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Although delete still doesn''t work. It seems to route to the show page > instead of deleting and doing a redirect to the index. > -- > Posted viahttp://www.ruby-forum.com/.That''s an easy one. The default path helper for both of them is singular_path(id) The destroy action needs a :method => :delete wherever it''s used <%= link_to(''verwijder'', user_path(user.id), :confirm => ''Weet je het zeker?'', :method => :delete) %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---