Giter Site home page Giter Site logo

refactoring-views-with-helpers-lab-v-000's Introduction

Refactoring Views With Helpers Lab

Objectives

  1. Review creating associated objects
  2. Write a helper to conditionally display different links
  3. Use the helper in multiple views

Song Library

In this lab, we're going to augment our song library to show the artists associated with songs, and use helpers to display different links based on whether or not a song is associated with an artist.

When we add songs to our library, we want to be sure to include the artist so that we can keep things organized. Sometimes, however, we might be in a hurry and don't know the artist off the top of our heads, so we leave it blank.

When we display the song library, we want to include the artist, but if there's no artist associated, we want to prompt the user to add one, because we don't want to contribute to the global iTunes library "Unknown Artist" epidemic.

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.

  1. Write the code to get (artist_name) and set (artist_name=) the Artist associated with a Song model.
  2. Write a helper method to display the artist for a song, with the following considerations:
  • Put the method in the appropriate helper file following the principle of Separation of Concerns
  • Name the method display_artist
  • If the artist name is not nil, return a link to the artist's show page.
  • If the artist name is nil, return a link to the song's edit page, with a link text of "Add Artist"
  1. Use the helper to display the artist on the song show and index pages.
  2. Make sure all tests pass then do this: Dancing Daft Punk

View Refactoring Views With Helpers Lab on Learn.co and start learning to code for free.

refactoring-views-with-helpers-lab-v-000's People

Contributors

annjohn avatar scottcreynolds avatar blake41 avatar brennenawana avatar bhollan avatar pletcher avatar dom-mc avatar jmburges avatar

Watchers

James Cloos 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.