Makeup Review App

Rupinder Kaur
5 min readJul 23, 2021

--

This is my Phase3 Flatiron School project. This time i built a Makeup review app. We have bunch of brands and products, where user can give their reviews about products. I also used search scope method where user have ability to search for products from their product page. i can honestly say that this is also difficult task to do. The main understanding of the rails is understanding the MVC pattern. MVC divides your application into parts Models, Controller and Views , that are dependent and connected to each other. Each design patterns have their own functionality to manage the app in proper ways. The MVC pattern helps in separating the display and the data and allow modification in each data without affecting others. It is mostly used for developing Graphical User Interface. Understanding these design pattern is easy and simple.

The requirements to complete this projects are:-

  1. Use the Ruby on Rails framework.
  2. Your models must:

• Include at least one has_many, at least one belongs_to, and at least two has_many :through relationships

  • Include a many-to-many relationship implemented with has_many :through associations.

3. Your models must include reasonable validations for the simple attributes.

4. You must include at least one class level ActiveRecord scope method.

5. Your application must provide standard user authentication, including signup, login, logout, and passwords.

6. Your authentication system must also allow login from some other service. Facebook, Twitter, Foursquare, Github, etc…

7. You must include and make use of a nested resource with the appropriate RESTful URLs.

8. Your forms should correctly display validation errors.

9. Your application must be, within reason, a DRY (Do-Not-Repeat-Yourself) rails app.

Firstly i focused on outlining my models and their relationships. To meet the requirements of “user submittable attribute” for the join table, i decided users to write reviews on products and can see all products they reviewed.

I used rails generator to built model, controller and migration designs pattern. Rails generator also give us a database migration to alter the database schema.

Specifying Nested routes

If we look again at our models, we see that an brand has_many :products and product belongs_to brand. Since a product can logically be considered a child object to an brand, it can also be considered a nested resource of an author for routing purposes. Nested resources give us a way to document that parent/child relationship in our routes and our URLS.

Now , we added do..end can pass it a block of its nested routes. Under that, we still have our regular resourced :products routes because we still want users to see all products , create and edit and update products and so on outside of the context of an author. Now, we have to update our products controller to handle the nested resource we just set up. I updated products index, we are first checking to see if it is nested url. If it is nested then we find the brand in the database and then fetch all the products for that brand. If not nested then we fetch every object.

Nesting routes is a powerful tool that helps you keep your routes neat and tidy and better than dynamic route segments for representing parent/child relationships in your system.

Helpers & partials

Helpers are methods that allow you to encapsulate tasks for reuse throughout your views. They can also help you extract logic from your views, like conditional statements. Rails provides handy pre-built view helpers that assist with common tasks like building forms and creating HTML links. If the built-in helpers don’t fit your needs, you can also build your own custom helper methods. Implementing partials and helpers also helpfull to abstract my code and came in handy to keep my views DRY. Through the use of partials , i’m able to render the form for brand, products and reviews new and edit form. For cleaner code and code re-use, partials are used to aviod repeating the same code.

Scope methods

I used scope methods to show products by order_by_price and brands by organised with order by name.

scope :order_by_name, -> {order(“lower(name)”)}

scope :order_by_price, -> {order(:price)}

scope :search_by_name, ->(name) {where(“name like ?”, “%#{name}%”)}

In search scope method, we can search any product by writing product name in the search tag.

Hit Api

I fetch an database from https://makeup-api.herokuapp.com/ to get all results for products and brands. I used an HTTP Gem, which is an easy-to-use client library for making requests from ruby. To obtain an HTTP::Response object instead of the response body, all we have to do is omit the #to_s on the end:

This project as difficult as other projects but only way to learn is to utilize google , youtube to help through . Honestly, my biggest challenge came with figuring out the logic of certain actions when nesting was involved. After i finish with my all code , it was time to style my app with CSS. I got help through google to look around to style my website with many style elements.

Thank you for reading this blog.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Rupinder Kaur
Rupinder Kaur

No responses yet

Write a response