Tuesday, January 27, 2009

Changing Select Box data via Ajax from Rails

I needed to change the items in a select input control in response to the changing selection of another select input control.

So I registered a change event on the first select input control by:


$('#control_strategy').delegate('change', '#control_strategy', function(){
get_possible_durations();
});


The get_possible_durations function is as follows:


function get_possible_durations() {
data = {};
data['control_strategy_id'] = $('#control_strategy').val();

$.get("/control_events/duration_increment.js?" + jQuery.param(data), null, function(data) {
var options = '';
data = eval(data);
$.each( data, function( n ) {
options += '<option value="' + this[1] + '">' + this[0] + '</option>';
} );
$( "#duration" ).html( options );
});
}



This function simply makes an ajax call passing in a single parameter based on the value in first drop down. It then responds to the completion of the ajax call by building an "option list" and replacing the html of the second select input control.

The Controller Method that I call is simply:


def duration_increment
data = durations_for_strategy(params[:control_strategy_id])
respond_to do |format|
format.js {render :json => data.to_json}
end
end


The duration_for_strategy method just builds a nice nested array of the data that I need to show...the important part is:



values = []
.
.
.
values << [pretty_up(last_time_added), last_time_added]


Pairing and Code Quality

A simple reminder...

We are pretty much a pair programming shop...although we have one project that started with a single person and has evolved to be a fairly complicated piece of code.

The developer on the project is very talented but we don't have the same level of testing rigor woven into the rhythm of that project as it in our core development effort. As a result we are seeing late breaking defects that are easy to fix, but annoying to our client.

The fix is going to be bringing that project into our main effort and ensuring that someone is always pairing when work is done on either.

Friday, January 23, 2009

Being a Pro with your tools

One of my team member said something very poignant to me during an annual review this week. When I asked him what I should work on improving this year he asked that all of us make a concerted effort to become more adept with our chosen editor.

I had always thought that my Textmate skills were passable, but after I thought about his comment, I realized how much room for improvement really existed.

So here begins a journey in shortcuts, macros and bundles that will hopefully land me in a more productive stance. Who knows....I might even be dragged into learning VIM...nahhhh.