Params in the route

Ilknur Eren
Dec 4, 2017 · 1 min read

Today we learned how we can interact with the URL and the JSON data we render in chrome. There are multiple ways to interact with our URL. Following is code for one way to interact with our URL.

In the routes server, we need to put a placeholder for our URL like so:

get '/name/:wildcard' => 'names#get_name'

In our controller, we can plug in our method like so:

def get_name
p "What does your name start with?"
this_name = params[‘wildcard’]
if this_name == “a”
p “your name starts with the first letter of the alphabet!”
else
end
render json: {message:this_name}
end

We assign the this_name variable to params['wildcard'] . Later when we type out our URL with anything next to name/_____ , this_name method will be whatever we fill out and our message will be that!

Ilknur Eren

Written by

Interests: Tech, Start Up, Education and Disability

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade