Params Flashcards
What are Params?
Params is a hash made available for you in a Get request, post form data or through a url.
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.
The params hash comes from a query string in a GET request, or though an HTML form in a post request.
What are the HTTP verbs explain briefly what each one does?
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.
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.
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