Archive for the ‘Ruby’ Category

Today I had a log table report query that contained a nested query. It was taking ages (5mins) to complete. I investigated indexes which I had been meaning to look at for a while. Anyway I managed to bring down the query to 0.04s – I now have much love for indexes!!
Basic MySQL syntax:
1CREATE INDEX [...]

Add this to your ~/.bash_profile (~/.profile on OSX) and gain a ‘trs’ shortcut to reboot mod_rails. Bliss ;]
1alias trs=’touch tmp/restart.txt’

When rendering a collection of partials in Rails you can access a sneaky iteration counter from inside each partial using the partial name appended with _counter:
So in the view / partial that calls the collection of partials:
1<%= render :partial => "partial_name", :collection => stuff_to_loop_over %>
Then in your called partial:
12<%= partial_name_counter %>
# Outputs the count 0,1,2,3,4 [...]


top