1. Serving Multi-file Zips with Rails

    The Prob Suppose you are have an Axlsx report served with axlsx_rails, and you need to generate it for multiple models, and serve them all in one request. You can't simply call render for each: def download_report params[:user_id].each do |user_id| @user = User.find user…


  2. Rendering a Rails View from a Script

    The Problem Sometimes you want to render a template inside of a script. Suppose you need to cache the generated output, say a web page or a spreadsheet, and save it to disk. So how do we do this? It is of course easy to do inside a controller. Call…


  3. ActiveRecord#freeze

    Blissful Ignorance I have an ActiveRecord model that saves the going Canadian exchange rate when needed. I (in)conveniently called that method freeze: def freeze if unit_order unit_order.set_freight if Maybe(unit_order.dealer).canadian? unit_order.set_exchange_rate(true) end unit_order.save end end…


  4. Prawn: Turning Tables Part 2

    This is the second post in a series on my changes to Prawn to support rotated table text. Prawn is a fast ruby gem for creating acrobat files. I use it to create reports and invoices. However, it does not have support yet for rotating table text. View the last…


  5. Ruby Hash Defaults and Group By

    I do a lot of processing of legacy data, converting it to new databases. Usually this data needs to be indexed by some value, and a hash is a perfect solution. The Hash class lets you specify defaults that can save many keystrokes and make your code easier to read…


  6. Why I Love Rails

    DHH is taking quite a bit of heat lately with is strong opinions regarding TDD.1 So far I've mostly seen quips that DHH doesn't know how to program, or people discounting his ideas because he always has strong opinions. Many fail to reproduce what he was trying to say…