Params in the route

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!”
render json: {message:this_name}

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!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.