Hi I am fairly new to Rails but I have done a lot of stuff in PHP. I''m not sure why this isn''t working, but I have tried a lot of ways to do the same thing. Please let me know what you think. What I''m trying to do is integrate Google Maps into a Rails. Basically, when a user moves a marker, an Ajax.Request/Updater (for debugging purposes) is sent to my controller. However, the code in my controller is not doing what it should be doing. I want it to Select the old row and Update it with the new information. Here is my code: Controller: def setmarker usr_marker = Marker.find(:all, :conditions => "latitude ''#{params[:oldLat]}'' AND longitude = ''#{params[:oldLng]}''") Marker.update(usr_marker.id, {:latitude => params[:newLat], :longitude => params[:newLng]}) render_text usr_marker.latitude end Ajax.Updater (for debugging purposes... switching back to Ajax.Request later) new Ajax.Updater("content", "/members_home/setmarker", { method: ''post'', parameters: "oldLat=" + oldLatLng.lat() + "&oldLng=" + oldLatLng.lng() + "&newLat=" + marker.getPoint().lat() + "&newLng=" + marker.getPoint().lng(), insertion: Insertion.Bottom } The Ajax stuff works as it should, here''s a bit of the error which I am having: Parameters: {"oldLng"=>"-79.6903", "newLng"=>"-79.74494934082031", "oldLat"=>"43.4667", "newLat"=>"43.47733866178997"} And I am having multiple errors, but the one I am having right now is ActiveRecord::RecordNotFound when the record should definately be there. Thanks in advance! tazsingh -- 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 -~----------~----~----~----~------~----~------~--~---
MichaelLatta
2007-May-28 00:48 UTC
Re: Help with MySQL Select, Update and Ajax.Request/Updater
For one thing find(:all, ...) can return multiple rows so the result is an array. I would suggest that rather than using Marker.update on the class that you simply update the objects returned from find. After changing the attributes you wish to update, just call save on the modified objects. Michael On May 27, 4:22 pm, Taz Singh <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > > I am fairly new to Rails but I have done a lot of stuff in PHP. I''m not > sure why this isn''t working, but I have tried a lot of ways to do the > same thing. Please let me know what you think. > > What I''m trying to do is integrate Google Maps into a Rails. Basically, > when a user moves a marker, an Ajax.Request/Updater (for debugging > purposes) is sent to my controller. However, the code in my controller > is not doing what it should be doing. I want it to Select the old row > and Update it with the new information. Here is my code: > > Controller: > def setmarker > usr_marker = Marker.find(:all, :conditions => "latitude > ''#{params[:oldLat]}'' AND longitude = ''#{params[:oldLng]}''") > Marker.update(usr_marker.id, {:latitude => params[:newLat], > :longitude => params[:newLng]}) > render_text usr_marker.latitude > end > > Ajax.Updater (for debugging purposes... switching back to Ajax.Request > later) > new Ajax.Updater("content", "/members_home/setmarker", { > method: ''post'', > parameters: "oldLat=" + oldLatLng.lat() + "&oldLng=" + > oldLatLng.lng() + "&newLat=" + marker.getPoint().lat() + "&newLng=" + > marker.getPoint().lng(), > insertion: Insertion.Bottom > > } > > The Ajax stuff works as it should, here''s a bit of the error which I am > having: > Parameters: {"oldLng"=>"-79.6903", "newLng"=>"-79.74494934082031", > "oldLat"=>"43.4667", "newLat"=>"43.47733866178997"} > > And I am having multiple errors, but the one I am having right now is > ActiveRecord::RecordNotFound when the record should definately be there. > > Thanks in advance! > tazsingh > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---