Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class User < ApplicationRecord
validates :name, presence: true
validate :check_length
validate :check_birthday
validate :check_lengthphone
validate :check_phone

private
def check_lengthphone
if self.phone && self.phone.length!=10
self.errors.add :lengthphone,"sdt khong hop le"
end

end

def check_phone
if self.phone && self.phone[0].to_i != 0
self.errors.add :phone, "sdt khong co so 0 o dau"
end
end


private
def check_length
if self.name && self.name.length<10
self.errors.add :name, "t0000000en qua ngan"
end
end

def check_birthday
if self.birthday && (Date.today - 90.years > self.birthday.to_date || Date.today - 7.years < self.birthday.to_date)
self.errors.add :birthday, "be tuoi qua"
end
end
end
Binary file modified db/development.sqlite3
Binary file not shown.
6 changes: 6 additions & 0 deletions db/migrate/20170316073624_add_columns_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddColumnsToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :phone, :string
add_column :users, :birthday, :date
end
end
4 changes: 4 additions & 0 deletions db/migrate/20170316075247_add_column.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class AddColumn < ActiveRecord::Migration[5.0]
def change
end
end
65 changes: 65 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170316075247) do

create_table "checks", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "infopeople", force: :cascade do |t|
t.string "birthday"
t.string "numberphone"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "infos", force: :cascade do |t|
t.string "birthday"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "people", force: :cascade do |t|
t.date "birthday"
t.integer "numberphone"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "testinfos", force: :cascade do |t|
t.string "birthday"
t.integer "numberphone"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "tests", force: :cascade do |t|
t.string "birthday"
t.string "numberphone"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "phone"
t.date "birthday"
end

end
235 changes: 235 additions & 0 deletions log/development.log

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions test/fixtures/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
email: MyString

two:
name: MyString
email: MyString
9 changes: 9 additions & 0 deletions test/fixtures/contacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday:
numberphone: 1

two:
birthday:
numberphone: 1
9 changes: 9 additions & 0 deletions test/fixtures/humen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday:
numberphone: 1

two:
birthday:
numberphone: 1
9 changes: 9 additions & 0 deletions test/fixtures/infopeople.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday: MyString
numberphone: MyString

two:
birthday: MyString
numberphone: MyString
7 changes: 7 additions & 0 deletions test/fixtures/infos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday: MyString

two:
birthday: MyString
9 changes: 9 additions & 0 deletions test/fixtures/people.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday: 2017-03-15
numberphone: 1

two:
birthday: 2017-03-15
numberphone: 1
9 changes: 9 additions & 0 deletions test/fixtures/testinfos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday: MyString
numberphone: 1

two:
birthday: MyString
numberphone: 1
9 changes: 9 additions & 0 deletions test/fixtures/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
birthday: MyString
numberphone: MyString

two:
birthday: MyString
numberphone: MyString
9 changes: 9 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
email: MyString

two:
name: MyString
email: MyString
7 changes: 7 additions & 0 deletions test/models/check_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CheckTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/contact_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ContactTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/human_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class HumanTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/info_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class InfoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/infoperson_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class InfopersonTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/person_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class PersonTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/test_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class TestTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/testinfo_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class TestinfoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end