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

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

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. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs