A Fresh Cup is Mike Gunderloy's software development weblog, covering Ruby on Rails and whatever else I find interesting in the universe of software. I'm a full-time Rails and iOS developer.


A Fresh Cup

Notes on Rails and other development


Double Shot #341

Hopefully I will shake off the post-turkey stupor and write some code today.

  • RubyConf08 Videos - Confreaks has got most of them processed and posted now, with more formats to come.

  • A Byte of Vim - Free eBook on using the Vim editor.

  • dj.god - The delayed_job god configuration used by github. This was a great help to me in setting up my own.

  • Gettin' less icky with the chronic - A way to make run all date attributes through chronic. I should take a closer look at this.
  • Wednesday


    Looks like I'm going to roll out at least one and possibly two Rails applications that use delayed_job for asynchronous background job processing. What I haven't figured out is a good server-side deployment strategy. If you have, I'd love to talk to you.

    Double Shot #340

    I'd forgotten how fun trying to pull all the pieces together on a last-minute high-pressure project could be.

  • Rubinius for the Layman, Part 3 - Try Rubinius in 20 minutes - Rubinius took a blow this week when Engine Yard let some folks go, but things are mature enough that you can see the current state of the project easily if you want.

  • If you use Mocha and RSpec then read this - Jake Scruggs points out a useful plugin if you're in this boat.

  • Calendar Date Select - Rails plugin for popup calendars. I used this in an app this week and so far it's working out nicely.
  • Tuesday

    Sorting ActiveRecord Objects

    I recently hit a situation where I needed to sort an array of ActiveRecord objects on a particular attribute. The catch was that in this case the array started out with the results of a find operation - but then it had a bunch more transient objects added to it that weren't part of the database. Fortunately the Array#sort method makes short work of this. Given an array a of objects with an entry_date attribute:

    [sourcecode language='ruby']
    a.sort! {|x,y| x.entry_date <=> y.entry_date}

    Because this was the only sort I needed on this particular model, I decided to push the operation right down into the model:

    [sourcecode language='ruby']
    class Receipt < ActiveRecord::Base
    def <=> (other)
    entry_date <=> other.entry_date

    Then the sort is much simpler:

    [sourcecode language='ruby']

    Note that this technique only makes sense if your array isn't coming straight from the database. If you are retrieving records from the database, you're better off including an :order clause in your finder to let the database do the sorting.

    Double Shot #339

    Too busy to do more than post a couple of links, alas.

  • Moving to Rails 2.2 Headaches - Vol 1 - Looks like mostly issues with various libraries not being ready yet.

  • jrails_in_place_editing - Now that it's been moved out of core Rails, there are a boatload of in-place edit plugins out there. This one seems to work OK in a project where we're using jQuery.