Why ?
To get an opinion of the provided massage from the employees. This system ensures to have a good quality service from the masseur and confidence from companies.
How
[ ] Create the Rating model. In the console : rails g model Rating rating:integer
[ ] Edit the generated migration. Add the following lines of code :
t.belongs_to :masseur, index: true, and t.belongs_to :employee, index: true
[ ] Edit the generated model. Add these lines :
validates :rating, presence: true, belongs_to :masseur, belongs_to :employee
[ ] In the MasseurProfile model, add the following code :
def average_rate
total=0
@masseur.ratings.each do |rating|
total = total + rating
end
average_rate_result = total / @masseur.ratings.count
# Get a rounded result
average_rate_result %= '%.2f'
end
(More details about the last line at the third element of the reading list)
Test the system in console :
>> rails console --sandbox
>> Masseur.create(email: "test@example.com", password: "123456", password_confirmation: "123456")
# Then create MasseurProfile : take the ID of the last created masseur
>> Masseur.last
>> MasseurProfile.create(masseur_id: the_id_of_the_last_created, first_name: "toto", last_name: "test", description: "Text written to fill the description attribute text text text", authorized: true)
# Do the same steps to create the Employee
# 1. Employee.create(...)
# 2. EmployeeProfile.create(...)
# Test the Rating system :
# Create multiple employees :
>> Rating.create(employee_profile: Employee.last, masseur_profile: Masseur.last, rating: 4)
>> Rating.create(employee_profile: Employee.last, masseur_profile: Masseur.last, rating: 2)
>> Rating.create(employee_profile: Employee.last, masseur_profile: Masseur.last, rating: 3)
# Calculate rating :
>> MasseurProfile.last.average_rate
# You should have this result : `3`.
Must Have
A functionnal rating system to allow employees rating masseurs.
Why ? To get an opinion of the provided massage from the employees. This system ensures to have a good quality service from the masseur and confidence from companies.
How
rails g model Rating rating:integer
t.belongs_to :masseur, index: true
, andt.belongs_to :employee, index: true
validates :rating, presence: true
,belongs_to :masseur
,belongs_to :employee
(More details about the last line at the third element of the reading list)
Test the system in console :
Must Have A functionnal rating system to allow employees rating masseurs.
Reading List