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.
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.
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.
A nested new route with form will be following.
scope method
Rather than using native Ruby method, this time, I've added two scope method; Most Reviewed hairstylists and High-rated reviews.
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)