Skip to content

Instantly share code, notes, and snippets.

@Leejojo
Created July 6, 2016 20:07
Show Gist options
  • Save Leejojo/7e66c2eea0665e8ec21ff6c190767603 to your computer and use it in GitHub Desktop.
Save Leejojo/7e66c2eea0665e8ec21ff6c190767603 to your computer and use it in GitHub Desktop.
Stores & Employees (CR)
class Employee < ActiveRecord::Base
belongs_to :store
validates :first_name, presence: true
validates :last_name, presence: true
validates :hourly_rate, numericality: { greater_than: 40, less_than: 3000 }
validates :store_id, presence: true
end
require_relative '../setup'
puts "Exercise 1"
puts "----------"
# Your code goes below here ...
Store.create(
name: "Burnaby",
annual_revenue: 300000,
mens_apparel: true,
womens_apparel: true
)
Store.create(
name: "Richmond",
annual_revenue: 1260000,
mens_apparel: false,
womens_apparel: true
)
Store.create(
name: "Gastown",
annual_revenue: 190000,
mens_apparel: true,
womens_apparel: false
)
puts Store.count
require_relative '../setup'
require_relative './exercise_1'
puts "Exercise 2"
puts "----------"
# Your code goes here ...
@store1 = Store.find(1)
@store1.name = "Queen West"
@store1.save
@store2 = Store.find(2)
require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
puts "Exercise 3"
puts "----------"
# Your code goes here ...
@store3 = Store.find(3)
@store3.destroy
puts Store.count
require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
puts "Exercise 4"
puts "----------"
# Your code goes here ...
Store.create(
name: "Surrey",
annual_revenue: 224000,
mens_apparel: false,
womens_apparel: true
)
Store.create(
name: "Whistler",
annual_revenue: 1900000,
mens_apparel: true,
womens_apparel: false
)
Store.create(
name: "Yaletown",
annual_revenue: 430000,
mens_apparel: true,
womens_apparel: true
)
@store4 = Store.find(4)
@store5 = Store.find(5)
@store6 = Store.find(6)
@mens_stores = Store.where(mens_apparel: true)
@mens_stores.each do |store|
puts "#{store.name} #{store.annual_revenue}"
end
@womens_stores = Store.where(womens_apparel: true).where('annual_revenue < 1000000')
@womens_stores.each do |store|
puts "#{store.name} #{store.annual_revenue}"
end
require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
puts "Exercise 5"
puts "----------"
# Your code goes here ...
puts Store.sum(:annual_revenue)
puts Store.average(:annual_revenue)
puts Store.where('annual_revenue >= 1000000').count
require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
puts "Exercise 6"
puts "----------"
# Your code goes here ...
@store1.employees.create(
first_name: "Michael",
last_name: "Jackson",
hourly_rate: 1000
)
@store2.employees.create(
first_name: "Janet",
last_name: "Jackson",
hourly_rate: 1200
)
@store4.employees.create(
first_name: "Elivs",
last_name: "Presley",
hourly_rate: 800
)
@store1.employees.create(
first_name: "Bob",
last_name: "Dylan",
hourly_rate: 900
)
@store1.employees.create(
first_name: "Whitney",
last_name: "Houston",
hourly_rate: 1000
)
@store5.employees.create(
first_name: "David",
last_name: "Bowie",
hourly_rate: 1300
)
@store6.employees.create(
first_name: "Aretha",
last_name: "Franklin",
hourly_rate: 1000
)
@store4.employees.create(
first_name: "Johnny",
last_name: "Cash",
hourly_rate: 1100
)
@store2.employees.create(
first_name: "Tina",
last_name: "Turner",
hourly_rate: 1600
)
@store4.employees.create(
first_name: "Stevie",
last_name: "Wonder",
hourly_rate: 1300
)
@store1.employees.create(
first_name: "Dolly",
last_name: "Parton",
hourly_rate: 2000
)
@store1.employees.create(
first_name: "Joanna",
last_name: "Lee",
hourly_rate: 20
)
require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
require_relative './exercise_6'
puts "Exercise 7"
puts "----------"
# Your code goes here ...
puts "What's the name of the store?"
input = gets.chomp
new_store = Store.create(name: input)
puts new_store.errors.messages
require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
require_relative './exercise_6'
puts "Exercise 7"
puts "----------"
# Your code goes here ...
puts "What's the name of the store?"
input = gets.chomp
new_store = Store.create(name: input)
puts new_store.errors.messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment