Saturday, December 24, 2011

JQTouch and Google Maps API Rendering Issues

Really quick one today. Today I implemented Google Maps into my JQTouch webapp using the Google Maps Javascript API V3.

Seemed easy enough except I was having a lot of rendering issues with the Google Maps (lots of gray areas where maps weren't rendering).

The key is, the Map constructor for Google Maps takes into account a div and renders a map in it. Let's call that the "map-div".

The issue was that I was using Javascript to render the map, then I called a jQT.goTo("#mappage") which changed the positioning of the map-div tag where the map was being rendered.

Quick solution: navigate to the page where the map-div is first - then do the Google Maps rendering. In my case, I had to call the jQT.goTo("#mappage") first, then I did my Google Maps rendering. Problem solved. Maps rendered gorgeously!

Friday, December 2, 2011

jQuery AJAX Post to a Rails Create Function

Alright, I was going to do this posting when I discovered my solution, but I got super busy and never got around to it.

Basically the problem I ran into was knowing how to call Rails Create function using JQuery AJAX. There were a few parameters I didn't know about - like what was the URL, what was the type of AJAX call, how did I pass the data etc.

So, my setup was that I had a controller for my sessions and I was using rails "resources" routing to generate the routes for it. The "create" action of the SessionsController required a "session" object that contained an "email" and a "password" and the session was expected to be incoming via the parameters. That is, the SessionController.create was looking for params[:session][:email] and params[:session][:password].

So how do I get all this to happen with an AJAX JQuery call:

type: "POST",
url: "/sessions",
dataType : "json",
data: { session : { email : var_email, password : var_password } },
success : function(data, textStatus, jqXHR) {
error : function(jqXHR, textStatus, errorThrown) {

The thing that took me a while to figure out was the URL and the type and the data. Probably would have helped if I reviewed my "resources" routing in Rails and also new that you could pass a JSON object to a Rails controller.