Giter Site home page Giter Site logo

routing-nested-resources-lab-atlanta-web-career-121018's Introduction

Nested Resource Routing Lab

Objectives

  1. Write nested routes
  2. Filter data sets based on nesting
  3. Handle errors in nested routes

Overview

In this lab, we're going to extend our song library using nested resources to build new routes for our artists and songs. Then, we'll use the URL helpers in our views to expose these new routes.

We'll also be handling errors when nested resources aren't found so that we can provide a more professional experience to our users.

Instructions

The base models, controllers, views, and other files have been provided. There are tests for the lab in the spec directory. You can run tests with the rspec command.

Remember to rake db:seed to set up a starter song library!

  1. Create nested resource routes to show all songs for an artist (/artists/1/songs) and individual songs for that artist (/artists/1/songs/1). Restrict the nested songs routes to index and show actions only.
  2. Update the artists index view to use the new nested resource route URL helper to link to the index of all songs by that artist.
  3. Update the artists show view to list each song for that artist, and use the new nested resource route helper to link each song to its corresponding show page.
  4. Update the songs_controller to allow the songs#index and songs#show actions to handle a valid song for the artist.
  5. In the songs#index action, if the artist can't be found, redirect to the index of artists, and set a flash[:alert] of "Artist not found."
  6. In the songs#show action, if the song can't be found for a given artist, redirect to the index of the artist's songs and set a flash[:alert] of "Song not found."
  7. Make sure all tests pass; then, party down!

Party Down

Hints

  1. For a refresher on the use of flash, see the ActionController RailsGuide.
  2. Remember when filtering nested resources to query for the children through the parent, e.g., @artist.songs.find_by(id: ...)
  3. There's more than one way to ride the Rails. You could handle not being able to find a record by using rescue ActiveRecord::RecordNotFound, or you could try using find_by(id: id) instead of find() and checking to see whether the result is nil.

routing-nested-resources-lab-atlanta-web-career-121018's People

Contributors

annjohn avatar bal360 avatar blake41 avatar dependabot[bot] avatar jmburges avatar lizbur10 avatar maxwellbenton avatar scottcreynolds avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.