From b58325439788349ee88aa96c5b502534f036b3c5 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 25 Jan 2014 14:56:31 -0600 Subject: [PATCH] create colors from rake --- app/models/color.rb | 2 ++ lib/tasks/colors.rake | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 lib/tasks/colors.rake diff --git a/app/models/color.rb b/app/models/color.rb index 37f09e7b..75f58516 100644 --- a/app/models/color.rb +++ b/app/models/color.rb @@ -5,6 +5,8 @@ class Color < ActiveRecord::Base scope :basic, where(:basic => true) scope :standard, where(:standard => true) scope :nonstandard, where(:standard => false) + + validates :name, presence: true def as_json(options={}) {:id => id, :name => human_name} diff --git a/lib/tasks/colors.rake b/lib/tasks/colors.rake new file mode 100644 index 00000000..efe22f02 --- /dev/null +++ b/lib/tasks/colors.rake @@ -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