Rails Resource Feeder Fun

27 Sep 2006

I had my first chance to use the new resource feeder yesterday while working on Tesly Jr. (yet to be announced product — contact me to learn more if you’re interested), and I thought I’d write up a quick example of how it’s used. The disclaimer to this post is that the resource feeder plugin is still quite new, and this example could become obsolete at any time.

There’s already a blog post about using this plugin, but I wanted to show something else — an answer to a question I’m sure will pop up again and again in #rubyonrails when people start really using this plugin: how do you customize the contents of the feed with multiple attributes from the model? It’s as simple as passing a proc in to the feeder:

class TestRunsController < ApplicationController
  def feed
    render_atom_feed_for TestRun.find(:all, :include => :test_plans, :order => ‘test_runs.created_at desc’, :limit => 50),
      :item => {
        :title => ‘Test run execution’,
        :description => Proc.new {|r| "Executed test plans: #{r.test_plan_names}

\n\nPass percentage: #{r.percentage.round}%"
}
      }
  end
end


Using Gruff and RMagick

16 Jun 2006

I’m working my presentation for RailsConf and wanted to make a fancy chart using Gruff. I hadn’t gotten around to installing RMagick on my MBP yet, so I was curious to see how it would go…

Well, it was incredibly easy, since I had previously used DarwinPorts to install Ruby:

sudo port install ghostscript
sudo port install rb-rmagick

That’s it. :)



<3 Ruby

22 Mar 2006

Today in #rubyonrails someone asked if there was a convenient way to append something (like a /) to a string if it wasn’t already there. I couldn’t think of one, so I wrote one:

class String
  def append_unless_ends_with!(string)
    self[-string.length..-1] == string ? self : self < < string
  end
end

I love ruby. :)