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