Coder Social home page Coder Social logo

displaying-associations-rails-lab's Introduction

Displaying Associations Rails

In the previous unit, we used validations and forms to create a management dashboard for songs and artists. Now we're ready to start connecting those models and using their relationships to display more interesting data.

  • In the controllers, this lab will require you to write show and index actions for both Song and Artist.

  • You'll need to add a foreign key by writing your own migration.

  • You'll need to set up the association in the model classes.

  • You'll need to format and link to the songs and artists according to the specs.

Additionally, you'll find that the specs require two special methods, Artist#song_count and Song#artist_name. These methods are meant to protect the views from complexity that belongs in the model.

They are also a great example of a software design principle called the Law of Demeter, which is sometimes called the "one dot" rule in object-oriented languages like Ruby. In other words, ruby user.best_friend is better than ruby user.friends.find_by(best: true) because all of the "friend"-related complexity is hidden away within the user model. This protects user-related code from future changes to friend functionality.

For example, if the above architecture changed such that best friendship was determined by the highest "friendship" value instead of a boolean best flag, the "two-dots" code would need to be changed everywhere, but the first snippet, which obeys the Law of Demeter, hides that complexity in the User#best_friend method, whose definition can be changed without having to track down and update every single usage.

displaying-associations-rails-lab's People

Contributors

annjohn avatar aviflombaum avatar changemewtf avatar danielseehausen avatar dependabot[bot] avatar gabriel-demes avatar gj avatar hyeokjungkim avatar ipc103 avatar j-shilling avatar jmburges avatar lizbur10 avatar lkwlala avatar maxwellbenton avatar mendelb avatar morgvanny avatar nathaniel-miller avatar pletcher avatar rrcobb avatar victhevenot avatar williambarela 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.