Last active
December 20, 2015 11:59
-
-
Save markmccanna1/6127437 to your computer and use it in GitHub Desktop.
students.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative '../config' | |
# this is where you should use an ActiveRecord migration to | |
class CreateStudents < ActiveRecord::Migration | |
def change | |
# HINT: checkout ActiveRecord::Migration.create_table | |
create_table :students do |t| | |
t.string :first_name | |
t.string :last_name | |
t.string :gender | |
t.date :birthday | |
t.string :email | |
t.string :phone | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative '../../db/config' | |
require 'time' | |
class Student < ActiveRecord::Base | |
# implement your Student model here | |
attr_accessor :first_name, :last_name, :birthday, :email, :phone, :gender | |
validates :age, numericality: { only_integer: true, | |
greater_than: 4 } | |
validates :email, format: { with: /.+@.+[.].{2,}/, | |
message: "wrong format, biatch"} | |
validates :email, :uniqueness => true | |
validate :lemme_get_yo_numba | |
# def initialize(options = {}) | |
# self.first_name = options[:first_name] | |
# self.last_name = options[:last_name] | |
# self.birthday = options[:birthday] | |
# self.email = options[:email] | |
# self.phone = options[:phone] | |
# self.gender = options[:gender] | |
# end | |
def lemme_get_yo_numba | |
errors.add(:phone, "yo digits aint rite") if | |
phone.gsub(/\D/, "").length < 10 | |
end | |
def name | |
"#{first_name} #{last_name}" | |
end | |
def age | |
(Date.today - birthday).to_i/365 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment