create colors from rake
This commit is contained in:
parent
49a901abfb
commit
b583254397
2 changed files with 17 additions and 0 deletions
|
@ -5,6 +5,8 @@ class Color < ActiveRecord::Base
|
||||||
scope :basic, where(:basic => true)
|
scope :basic, where(:basic => true)
|
||||||
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}
|
||||||
|
|
15
lib/tasks/colors.rake
Normal file
15
lib/tasks/colors.rake
Normal 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
|
Loading…
Reference in a new issue