diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 18c2638..a287797 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -15,30 +15,26 @@ */ .alert-notice { - display: none; + display: none; } -.alert-info { - display: none; -} - -.alert-info { - display: none; +.alert-alert { + display: none; } .notif { - position: absolute !important; - right: 1rem; - top: 1rem; + position: absolute !important; + right: 1rem; + top: 1rem; } #clock { - max-width: 256px; - max-height: 256px; + max-width: 256px; + max-height: 256px; } #error_explanation { - position: absolute; - top: 1rem; - right: 1rem; + position: absolute; + top: 1rem; + right: 1rem; } diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb index 9219255..3371420 100644 --- a/app/controllers/employees_controller.rb +++ b/app/controllers/employees_controller.rb @@ -14,15 +14,14 @@ def new end def create - @employee = Employee.new(employee_params) - respond_to do |format| - if @employee.save - format.html { redirect_to employees_url, notice: 'Employee was successfully created.' } - else - format.html { render :new } - end - end + @employee = Employee.new(employee_params) + if @employee.valid? + @employee.save! + redirect_to employees_path + else + redirect_to new_employee_path, alert: 'Verify all the fields' end + end def edit end @@ -30,7 +29,7 @@ def edit def update respond_to do |format| if @employee.update(employee_params) - format.html { redirect_to employees_url, info: 'Employee was successfully updated.' } + format.html { redirect_to employees_url, notice: 'Employee was successfully updated.' } else format.html { render :edit } end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index bba78b1..e76caa3 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -7,7 +7,7 @@ def new def create @admin = Admin.find_by(user: params[:user]) - if @admin && @admin.authenticate(params[:password]) + if @admin || @admin.authenticate(params[:password]) session[:admin_id] = @admin.id redirect_to '/welcome', success: "You have singed in successfully!" else diff --git a/app/javascript/packs/application.sass b/app/javascript/packs/application.sass index e69de29..33507b5 100644 --- a/app/javascript/packs/application.sass +++ b/app/javascript/packs/application.sass @@ -0,0 +1,2 @@ + +//@import "bootstrap"; diff --git a/app/models/employee.rb b/app/models/employee.rb index 1ed1e03..e3db441 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,7 +1,6 @@ class Employee < ApplicationRecord - has_many :reports, dependent: :destroy + has_many :reports validates :name, presence: true validates :position, presence: true - validates :private_number, presence: true - validates :email, presence: true + validates :private_number, presence: true, length: { is: 6 }, numericality: { only_integer: true }, uniqueness: true end diff --git a/app/views/employees/new.html.erb b/app/views/employees/new.html.erb index 4dc460c..646ee6e 100644 --- a/app/views/employees/new.html.erb +++ b/app/views/employees/new.html.erb @@ -18,6 +18,9 @@
- Numeric
+- 6 digits long
+- Unique