Rails Quality Control Tip: Use Verify in Controllers

Have you found that any of your Rails projects get hits to controller methods that expect parameters? A neat way of handling this is the ActionController::Verification module.

Have you found that any of your Rails projects get hits to controller methods that expect parameters? A neat way of handling this is the ActionController::Verification module.
Have you ever tried concatenating your JavaScript and CSS files for performance improvements? The idea is that latency is a bigger issue than file size when loading web pages, so stuffing all your JavaScript into a monolithic file for deployment should improve performance.
I wrote a rake task to do this for some of my applications (such as tiktrac). This is slightly more cumbersome than a feature I spied in the ActionPack changelog:
With hpricot you can do anything!
puts ((Hpricot(open(URI.escape("http://www.google.com/search?q=#{term}"))))/"a.l").collect { |link| "#{link.innerHTML}: #{link.attributes['href']}" }.join("\n")
One of my commercial projects this year was to build an online ticket sales system for a large bar and venue company in London. The run up to Christmas was the big live test of the system, so they needed statistics on ticket sales.
Just for fun, I decided to make a Dashboard widget that used curl to fetch the current data from a script on their server. But you know what made this task 100% less painful? My old friend Prototype.js.
Apparently, Opera 9 supports Server–Sent Events which you can read about in the WHATWG Web Applications 1.0 specification. Their demo application is a little chat program, which is a very obvious example of the technology.
There’s many times when I’ve wanted to add this to my applications: in Bugtagger I have to ask the service if a new message from a customer has been posted to a bug, every n seconds. It would be far more efficient for the serve to send a message using this technology.
I needed a quick way of exporting data as zlib from a controller in Rails, so I came up with this:
def export
send_data compress_string(Document.find_all.to_xml), :filename => 'backup.xml.gz'
end
def compress_string(data)
gz = Zlib::GzipWriter.new(StringIO.new(''))
gz.write data
gz.close.string
rescue
gz.close
raise
end
Another way would be to use tempfiles with Tempfile — I wanted to benchmark and profile using files compared to StringIO, but that’ll be an exercise for another day.
Helipad is a little web notepad I wrote to throw to–do lists, notes, ideas and bits of code at. My idea was to make the perfect partner for my actual physical notepad.
Like everything I do, it has an API, and that allowed me to do something that I’ve found amazingly useful: load my vimrc remotely.

Imagine your own little mac os app written with the Camping framework, that you can easily share with other mac–weilding friends. It’s all possible with next to no ridiculous hacking at all!
A text editor is the programmer’s lathe, but unlike traditional engineering we can have limitless tools. The question is: how much time do you have to learn about them all?

I’ve created quite a few Rails projects over the last year, some commercial projects, and others are applications released under Helicoid. Here’s a few things I’ve found save time and help make projects as maintainable as possible.
You can refer to routes in your forms and links like this: document_edit_url(:id => document.id). Isn’t that much nicer than other means? It can often make code easier to understand quickly, thus helping maintainability.