Why ?
To make the company being able to send invites to the employees. The employees will connect and see informations about the reservation made by the company.
How ?
Create the model
[ ] run the command rails g model EmployeeProfile first_name:string last_name:string company_id:integer authorized:boolean
Migration editing :
go to the migration file generated by this command
[ ] get at the line t.boolean :authorized and edit it to get t.boolean :authorized, default: true.
[ ] after the previous t.boolean line, add the following line code : t.belongs_to :employee, index: true.
[ ] next, add the following line code : t.belongs_to :company_profile, index: true.
Model editing :
Go to the model file _masseurprofile.rb and write the following code :
[ ] validates :first_name, presence: true
[ ] validates :last_name, presence: true
[ ] validates :company_id, presence: true
[ ] validates :authorized, presence: true
[ ] belongs_to :employee
[ ] belongs_to :company_profile
Testing the model in console (we need the other following models to be created before these tests : Company, CompanyProfile).
Testing link to Employee devise model :
[ ] create a company : Company.create(email: "test@example.com", password: "123456", password_confirmation: "123456"). Then create the CompanyProfile : take the ID of the last created company Company.last, and next, CompanyProfile.create(company_id: the_id_of_the_last_company_created, name: "test", authorized: true).
[ ] Link the employee to the company : run rails console --sandbox and create a masseur : Employee.create(email: "test@example.com", password: "123456", password_confirmation: "123456"). Then test the EmployeeProfile creation : take the ID of the last created employee Employee.last, and next, EmployeeProfile.create(employee_id: the_id_of_the_last_created, first_name: "toto", last_name: "test", company_id: the_id_of_the_last_company_created, authorized: true)
Must Have
A complete EmployeeProfile model, connected to the Employee model made with devise. The EmployeeProfile model belongs to a company.
Why ? To make the company being able to send invites to the employees. The employees will connect and see informations about the reservation made by the company.
How ? Create the model
rails g model EmployeeProfile first_name:string last_name:string company_id:integer authorized:boolean
Migration editing :
t.boolean :authorized
and edit it to gett.boolean :authorized, default: true
.t.boolean
line, add the following line code :t.belongs_to :employee, index: true
.t.belongs_to :company_profile, index: true
.Model editing :
validates :first_name, presence: true
validates :last_name, presence: true
validates :company_id, presence: true
validates :authorized, presence: true
belongs_to :employee
belongs_to :company_profile
Testing the model in console (we need the other following models to be created before these tests : Company, CompanyProfile). Testing link to Employee devise model :
Company.create(email: "test@example.com", password: "123456", password_confirmation: "123456")
. Then create the CompanyProfile : take the ID of the last created companyCompany.last
, and next,CompanyProfile.create(company_id: the_id_of_the_last_company_created, name: "test", authorized: true)
.rails console --sandbox
and create a masseur :Employee.create(email: "test@example.com", password: "123456", password_confirmation: "123456")
. Then test the EmployeeProfile creation : take the ID of the last created employeeEmployee.last
, and next,EmployeeProfile.create(employee_id: the_id_of_the_last_created, first_name: "toto", last_name: "test", company_id: the_id_of_the_last_company_created, authorized: true)
Must Have A complete EmployeeProfile model, connected to the Employee model made with devise. The EmployeeProfile model belongs to a company.
Reading List