Created
December 27, 2009 02:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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