# Help with MySQL Select, Update and Ajax.Request/Updater

**URL:** <https://www.ruby-forum.com/t/help-with-mysql-select-update-and-ajax-request-updater/105248>\
**Category:** Rails\
**Created:** [May 28, 2007, 1:22am UTC](https://www.ruby-forum.com/t/help-with-mysql-select-update-and-ajax-request-updater/105248 "2007-05-28T01:22:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tazsingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e57/32.png) [@tazsingh](https://www.ruby-forum.com/u/tazsingh)\
**Post date:** [May 28, 2007, 1:22am UTC](https://www.ruby-forum.com/t/help-with-mysql-select-update-and-ajax-request-updater/105248/1 "2007-05-28T01:22:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tazsingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e57/32.png) [@tazsingh](https://www.ruby-forum.com/u/tazsingh)\
**Post date:** [May 28, 2007, 2:49am UTC](https://www.ruby-forum.com/t/help-with-mysql-select-update-and-ajax-request-updater/105248/2 "2007-05-28T02:49:17Z")

</div>

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 S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
