Params in Rails
The concept of params is still a little fuzzy to me, so I’m writing this article partly in hopes for a moment of clarity. I am on week 4 of coding bootcamp and details are becoming hazy. Bear with me, please.
From my understanding, params will allow you to make dynamic URLs through just one route. Params are basically just extra add-ons to an HTTP GET request, without needing to make a whole new route. It will turn a string in the URL into a hash as follows:
If you were to want to add more than one param it would look like:
The key=value pairing is written as a string, but Rails will convert that information into a hash. If you were to use a param in Rails to call a value it would look like:
Here is an example. Let’s say your browser sends this get request:
Here you are saying that
params[:cat] is “meow” and
params[:dog] is “woof”.
Hope this makes sense!