Params Flashcards

1
Q

What are Params?

A

Params is a hash made available for you in a Get request, post form data or through a url.

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

Where do Params come from and what are routing Params? What does it mean when your Rail’s application receives the following request for: GET /patients/17
it asks the router to match it to a controller action, in simpler words, the request is saying I want to request to see the page of the patient with an id of 17. This can come in hand if you want to view a page of a specific patient.

A

The params hash comes from a query string in a GET request, or though an HTML form in a post request.

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

What are the HTTP verbs explain briefly what each one does?

A

GET - Makes a request to a certain page

POST - Makes a request to store data in the database

PUT/PATCH - Makes a request to update existing data in the database

DELETE - Makes a request to delete exisiting data in the database.

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

Write an example of a POST request to create a blog post. What to write in your ArticleController and what to write in the view for creating a post.

A

Views Folder:
new.html.erb File:

Controller Folder:
articles_controller.rb File:

ArticleController < ApplicationController
def create
article = Article.create(article_params)
flash[:notice] = “Article was successfully added”
redirect_to article
end

private

def article_params
params[:article].permit(:title, :content)
end

end

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