Skip to content

Instantly share code, notes, and snippets.

@tfwright
Created December 27, 2009 02:01
Show Gist options
  • Save tfwright/264121 to your computer and use it in GitHub Desktop.
Save tfwright/264121 to your computer and use it in GitHub Desktop.
A collection of useful rake tasks that doesn't deserve real source control
namespace :db do
desc "Fetches records from the database and prints their attributes"
task :fetch, [:model, :conditions] => :environment do |t, args|
args.with_defaults(:conditions => "id = (SELECT MIN(id) from #{args.model.tableize})")
klass = args.model.classify.constantize
finder = (args.model.pluralize == args.model ? :all : :first)
records = klass.send(finder, :conditions => args.conditions)
puts records.to_yaml
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment