New guy question

I have been assigned the task of making our website interactive. (AJAX)
I have the web pages doing what I want them to do. The DB is mysql on
Linux.

I want to use the html to query and update the DB tables.

I am going to use Ruby.

Does anyone have any starter code out there for the CGI?

I don't know how to pass my variable in my HTML/JavaScript to the CGI
and then how do I access my DB and query under the passed value.

How will I pass the query back to the HTML/JavaScript.