Explaining Params in Sinatra

Antonio Esp
1 min readMay 22, 2021

Params is a hash where data is being passed. The data can be passed in a couple of ways. The first is through a form, and the second is through the URL.

My Workout Form

The values I enter here on the browser will be converted into a Params Hash when I click the “Create” button. The keys in the hash will be the name attribute on the Input Tags. The values in that hash will be the value attribute on the Input Tags.

After we click “create”, the code in the controller will use our Params to create the columns for that workout object. It will redirect to the Workout Show page. The URL it redirects to, will be something like /users/5. The 5 in the URL will also be part of the Params hash. I could access it by doing params[:id]. Then I would search my Workouts table for the object where the ID is the same as the one in my URL. I would then put that object into an instance variable, so I can use it in my View file. That view file will display all of my columns of that object through the instance variable I create in my controller.

--

--