Skip to content

Instantly share code, notes, and snippets.

View migration.rb
class CreateCategory < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :title, null: false
t.text :description, null: false
t.timestamps null: false
end
end
end
View seeds.rb
fruits = Category.create(title: 'Fruits', description: "Ain't no veggie")
veggies = Category.create(title: 'Vegetables', description: "Ain't no fruit")
fruits.items.create(title: 'Apple', price: 100, expire_at: DateTime.now, count_1: rand(1..5), count_2: rand(1..5), count_3: rand(1..5), count_4: rand(1..5), validated: true)
fruits.items.create(title: 'Pear', price: 150, expire_at: DateTime.now + 2.days, count_1: rand(1..5), count_2: rand(1..5), count_3: rand(1..5), count_4: rand(1..5), validated: false)
fruits.items.create(title: 'Orange', price: 100, expire_at: DateTime.now + 2.days, count_1: rand(1..5), count_2: rand(1..5), count_3: rand(1..5), count_4: rand(1..5), validated: true)
veggies.items.create(title: 'Cucumber', price: 100, expire_at: DateTime.now + 3.days, count_1: rand(1..5), count_2: rand(1..5), count_3: rand(1..5), count_4: rand(1..5), validated: true)
veggies.items.create(title: 'Carrot', price: 150, expire_at: DateTime.now + 4.days, count_1: rand(1..5), count_2: rand(1..5), count_3: rand(1.
View gist:ffc30779d6ba9a6142ee
[ ] [ 1] [ ] [ ]
[ ] [ 4] [ ] [ ]
[ ] [ ] [ 3] [ ]
[ ] [ ] [ 2] [ ]
-------------------
[ ] [ 1] [ ] [ ]
[ 5] [ 4] [ ] [ ]
[ ] [ ] [ 3] [ ]
[ ] [ ] [ 2] [ ]
-------------------