Coder Social home page Coder Social logo

phase-4-rails-route-params-lab's Introduction

Route Params Lab

Learning Goals

  • Create a dynamic route
  • Use the params hash in the controller

Introduction

We'll continue building our API for viewing student data. In this lesson, we'll add a route and controller action for displaying data about one individual student.

To get set up, run:

$ bundle install
$ rails db:migrate db:seed

This will download all the dependencies for our app and set up the database.

Instructions

In this lab, we'll add the last feature to our student management app. You will need to integrate the following scenario in your application:

  1. The user is able to go to a URL with the student's ID (i.e. /students/2) to receive information on the student.

  2. The application should render the values from the student record with the corresponding ID in the database.

You can try out your solution by running rails s and visiting localhost:3000/students/2 in the browser.

There are two failing RSpec specs in this lesson; you can find them in spec/requests/student_spec.rb. Make sure they pass without breaking the other tests. To complete this lesson, all specs should pass by running learn test.

Bonus: Query Params

If you've used other APIs, or investigated some URLs as you've browsed the internet, you may have noticed some URLs have this special syntax:

https://www.google.com/search?q=bread

That ?q=bread portion of the URL is known as a query string parameter. Query string parameters are another way of providing data in a request. They're structured as key-value pairs, like so:

/students?key1=value1&key2=value2

Rails gives us access to these query string parameters as part of the params hash:

params
# => { key1: "value1", key2: "value2" }

As a bonus deliverable:

Un-comment out the last test in /spec/requests/students_spec.rb to complete the bonus.

  1. Use query params in the index action to return a list of all students whose first or last name matches the query parameter.

Resources

phase-4-rails-route-params-lab's People

Contributors

ihollander avatar lizbur10 avatar daisysimy1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.