DEV Community


Posted on

Day 73 : #100DaysofCode - Prepared for Assessment

What did I do today? I added some of the final touches on my rails project, began to prepare for my rails assessment, and watched some Python videos.

Here are some of the questions that I reviewed:

What are the four most standard HTTP request?

  1. GET
  2. POST

What is the difference between authentication and authorization?

"Authentication means confirming your own identity, whereas authorization means being allowed access to the system. In even more simpler terms authentication is the process of verifying oneself, while authorization is the process of verifying what you have access to."

Pretty much, you may be able to log into the with authentication, but you should not be able to edit my post because you are not authorized.

What gem gives you password encryption and what methods does it provide?

Bycrypt gives us password encryption and the two methods that it gives us is the password equals method and authenticate method

def password=(pw)
    self.password_digest = Digest::SHA2.hexdigest(pw) #makes the password equal to the hashed pw
Enter fullscreen mode Exit fullscreen mode

The above hashes the password and sets it equal to pw/password_digest

def authenticate(pw) #takes in plain text pw
 Digest::SHA2.hexdigest(pw) == self.password_digest
Enter fullscreen mode Exit fullscreen mode

Makes sure that user password is correct. Either returns self or false

What does belongs_to and has_many give us?

Belongs_to is a macro that provides the user and user= method. -- user will return a user object. The method helps you with dealing with objects instead of ids.

User method

def user
    User.find_by(id: self.user_id)
Enter fullscreen mode Exit fullscreen mode

User= Method

User= Method
def user=(obj)
   self.user_id =
Enter fullscreen mode Exit fullscreen mode

A has_many association indicates a one-to-many connection with another model. You'll often find this association on the "other side" of a belongs_to association


u.todos #=> returns an array of todo objects
Enter fullscreen mode Exit fullscreen mode

How do you make a nested route in rails?

In your config/routes.rb, you would add a nested route with doing something similar to the following:

  resources :reviews do 
    resources :comments, only: [:index, :show]
Enter fullscreen mode Exit fullscreen mode

This will allow you to visit the following urls: localhost:3000/reviews/1/comments and localhost:3000/reviews/1/comments/3

I have more to review, but these are just some that I was told to review before my assessment.

As always, thanks for reading!


Top comments (0)