create colors from rake

This commit is contained in:
Emi Matchu 2014-01-25 14:56:31 -06:00
parent 49a901abfb
commit b583254397
2 changed files with 17 additions and 0 deletions

View file

@ -6,6 +6,8 @@ class Color < ActiveRecord::Base
scope :standard, where(:standard => true) scope :standard, where(:standard => true)
scope :nonstandard, where(:standard => false) scope :nonstandard, where(:standard => false)
validates :name, presence: true
def as_json(options={}) def as_json(options={})
{:id => id, :name => human_name} {:id => id, :name => human_name}
end end

15
lib/tasks/colors.rake Normal file
View file

@ -0,0 +1,15 @@
namespace :colors do
desc 'Create a color'
task :create, [:id, :name, :standard, :basic, :prank] => :environment do |t, args|
args.with_defaults(standard: true, basic: false, prank: false)
# TIL: ActiveRecord will convert strings to booleans automatically. Cool.
color = Color.new
color.id = args[:id]
color.name = args[:name]
color.standard = args[:standard]
color.basic = args[:basic]
color.prank = args[:prank]
color.save!
puts "Color #{color.inspect} created"
end
end