Rails Flashcards

1
Q

What is a router?

A

Router is something in rails that is supposed to determine who to send the http request to. Router takes the path and the method of the request into consideration. (i.e. path = users, method: get). What combinations of paths and methods are associated with which controllers and which actions of these controllers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a controller?

A

Responsible for controlling one resource. (users controller processes all requests that are about users). Fill out http response and give it back to the router

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are controller actions?

A

Methods defined on the controller. Router when it matches the path and the method.. Will initialize the controller and call the right action. So, if the router knew a path of users and a method of get was supposed to match the users controller and index action. it would then create a new instance of the users controller and then call the index action

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a routes.rb file?g

A

checks the list for path and methods to process http request.

Lives in config/routes.rb

Define name of html method and specify path its supposed to match
i.e. - get ‘superheroes’, to: ‘superheroes#index’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are views?

A

Dynamically generate html based on some information we get from our database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does REST / RESTful mean?

A

Representational state transfer. An agreed upon way to specify these routes, so that people can trust that it’s going to do the same thing across applications.

You can create resources: to create all restful routes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to create a database on Rails

A

Run bundle exec rails db:create
If you have migrations, run bundle exec rails db:migrate
If you have seeds, run bundle exec rails db:seed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a GET Request?

A

Without a wildcard (:id) It returns all entries in the database. With a wildcard it returns the entry in the database with the matching id in the wildcard

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a POST request?

A

Creates an entry in the resource

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a PATCH request?

A

Updating an entry in the resource with the given id. it is similar to put and you want to have both routes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a DELETE request?

A

Removes an entry from the resource with the given ID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are controller params?

A

Sort of an instance method in controllers. It is a has like object given to the controller by the router. It contains 3 things:

1) Query string
2) Request body
3) URL params / route params

When the route is matched the router will take the pieces above and will parse them. It will populate the params object with the key-value pairs that match accordingly. Now, Controller can use these params as a hash. You can treat params hash like a normal hash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly