DEV Community

Wonjin Cho
Wonjin Cho

Posted on

Rails Project - Rate My Hairstylist

Project Idea

For my third project, I decided to build rating and reviewing web application.

Relationship

I created 3 models; User, UserStylist, Stylist.
User will have many stylists and Stylist will have many User through user_stylists. UserStylist(which will be review/rating model) model will be a join of User and Stylist. It belongs to user and stylists.

Screen Shot 2021-05-16 at 3.51.48 AM

Data Migration

By using rails g resource function, it was really easy to create migrations. Since this project requires omniauth log in function, I've added "uid" and "provider" as user's attributes. I'll user Google omniauth login for my project.

Rested routes

Here are all the routes for this web application.

Screen Shot 2021-05-16 at 3.56.11 AM

There is a nested route for user_stylist. For example, "user/3/user_stylists/46" will be the review details page which is a show page of this user's review.

Screen Shot 2021-05-16 at 4.00.32 AM

A nested new route with form will be following.
Screen Shot 2021-05-16 at 4.03.57 AM

scope method

Rather than using native Ruby method, this time, I've added two scope method; Most Reviewed hairstylists and High-rated reviews.

Screen Shot 2021-05-16 at 4.10.44 AM
Screen Shot 2021-05-16 at 4.10.59 AM

Those are my code for the two scope method. First one shows top 5 most reviewed hair stylists name. The second code is for rating scope that means each hairstylist has their reviews with star rating and by using that star attribute, I defined scope method to show only 5 stars reviews.

Conclusion

By having the 'resources' keyword, rails sets up every 'RESTful' route associated with that model. The routes magic were the one that really shined for me. I had struggled a lot dealing with all of Rails server errors to get promptly worked this application; however, each time, I've learned more than one error since one error causes usually another error.

Top comments (0)