Archive

Archive for July, 2010

Ruby IDE : Redcar

July 30, 2010 Leave a comment

It has been sometime that I have been using Ruby and RoR and I have always felt a void when it comes to a good IDE (I use Windows and Ubuntu). I have tried RadRails, Komodo, e editor to name a few. Last year I tried Redcar and liked it over all others. It had problems(and it was not supported on Windows) but there was a lot of active development going on and it looked promising. Then, for the next few months I never got back much to Ruby and never looked for an IDE. Last night I happened to google again and take a look at Redcar. I was amazed at the changes. It had almost all the things that I needed. There had been development to support it on Windows as well. The installation was as simple as running 2 commands..

gem install redcar

redcar install

I created a shortcut on my desktop to call the command using a cmd script and used one of its png images(<ruby-home>\lib\ruby\gems\1.8\gems\redcar-0.3.8.4\plugins\application\icons) as an icon image. That is all the work I needed to do. Best of all it, runs on GPL. (Nothing better)

I decided to write this on my blog as an effort to help Redcar gain more audience. Apple users might call it a rip off or a clone of Textmate but I think Daniel Lucraft has done an excellent job.

Advertisements
Categories: IDE, Ruby Tags: , , , ,

AJAX using JQuery

July 12, 2010 Leave a comment

We follow the same steps as in the previous blog entry except that we use a different javascript framework this time. The only thing that changes is the javascript in the code.

The javascript function now changes to…


$.ajax({
url: "../upperCaseSubmit.do",
type: "GET",
data: $('#textForm').serialize(),
cache: false,
success: function (response) {
$('#result').html(response).fadeIn('fast');
$('#result').html(response).fadeOut(2000);
},
error: function(){
alert("Error in processing the request");
}
});

Note: I have included some animation (fadeIn and fadeOut) which is not there in the code I created with Prototype.
Ajax.Responders in Prototype can be replaced by Jquery’s Ajax Events.

Basic AJAX using Prototype

July 12, 2010 Leave a comment

We start by creating a basic maven project with Struts. The idea is to accept text in a html text box, make a round trip to the server , capitalize the text (upper case it) and send it back as the response to the client. Our action class UpperCaseAction will have the following code in the execute method. The UpperCaseForm will have just one String attribute , text.

UpperCaseForm upperCaseForm = (UpperCaseForm)form;
upperCaseForm.getText().toUpperCase();
PrintWriter pw = response.getWriter();
pw.write(upperCaseForm.getText().toUpperCase());
pw.close();


We will create a jsp with a simple text box and a button. The onclick event on the button will fire a function in javascript that will make the Ajax call. The following is code uses prototype.js that makes that call

new Ajax.Request('../upperCaseSubmit.do', {
 method : 'get',
 parameters: $('textForm').serialize(true),
 onSuccess: function(response) {
 $('result').innerHTML = response.responseText;
 },
 onFailure: function(){
 alert('Error in processing request ...');
 }
 });


The code is self explainatory. It makes a call to the action upperCaseSubmit using ‘GET’. We have one parameter that will be sent in the request, the text field. If the call is a success the function defined by onSuccess is executed and we replace the innerHTML of a div with the upperCase of the text we received back.
If the call fails, an alert message is displayed. The serialize method formats the form data into a string.

Prototype has some listener functionality that we can utilize to know when a AJAX call has been placed.
Using the following code, we can turn on an image if at least one AJAX call is pending.

Ajax.Responders.register({
 onCreate: function() {$('loading').show();} ,
 onComplete: function() {
 if(0 == Ajax.activeRequestCount)
 $('loading').hide();
 }
 });


We can easily create a loading gif that we can use in the image tag from here. http://ajaxload.info/