GithubHelp home page GithubHelp logo

racross1 / active-record-practice-playlister-static-generator-lab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-curriculum/active-record-practice-playlister-static-generator-lab

0.0 0.0 0.0 193 KB

License: Other

Ruby 99.78% HTML 0.22%

active-record-practice-playlister-static-generator-lab's Introduction

Static Playlister on ActiveRecord

Welcome to the Web

In this lab, you're going to make some sweet static websites. Static means no server is needed, so you're not using Rails or Sinatra. You're going to use ActiveRecord and ERB to generate regular html web pages.

Using ActiveRecord and ERB you'll create ERB template files that end in .html.erb where you can call your ActiveRecord models - Artist, Genre, and Song - to access all the information stored in your database.

ActiveRecord Associations

In this lab, you'll be recreating the basic functionality of Playlister using ActiveRecord associations. The point of your association is to let your program know that an artist has many songs and therefore those songs belong to that artist. An artist will also have many genres, which it will know of through songs, so artist.genres will return all of the artist's genres.

You'll have three models: Artist, Song, and Genre. The Artist and Genre models will each know about its associated songs and each other. To create these associations you will need to write proper migrations as well as ActiveRecord macros, which are special methods created by ActiveRecord's DSL.

The model tests will be calling methods that your models will have by default if your associations are correctly defined. You do not need to write those methods. Once your associations are defined you can run rake db:seed to seed your database with sample data.

Creating Your Associations

  • Create your models in app/models
  • Your models will need an instance method called to_slug for making urls
    • ex. an_artist.to_slug #=> kanye-west
  • Write migrations for your models and associations in db/migrations

ERB and Static HTML Sites

Embedded Ruby (ERB) is a way of running Ruby in non .rb files. You'll be making your own generator that will read an html.erb file to generate many static pages.

Folder structure

Your template files will be in the following structure:

app/views
├── artists
│   ├── index.html.erb
│   └── show.html.erb
├── genres
│   ├── index.html.erb
│   └── show.html.erb
├── index.html.erb
└── songs
    ├── index.html.erb
    └── show.html.erb

Your processed files will be in the following structure:

_site
├── artists
│   └── index.html
├── genres
│   └── index.html
├── index.html
└── songs
    └── index.html

Index Pages

There will be index pages for the top level as well as for each model; the index pages for the models will list all instances of that model

  • Your index pages should be called index.html.erb
  • The index page for the top level of app/views/ should have a link to each model and a count of total instances
    • ex. Artists - 42
  • Each model will have an index page in its appropriate folder in the app/views directory which lists every instance and links to each instance's show page

Show Pages

Each model will have a show page in app/views/<model>/ that renders information specific to that instance.

  • The show pages should be called show.html.erb
  • Artist show pages will have the instance's name and will list and link to its genres and songs.
  • Genre show pages will have the instance's name and will list and link to its artists and songs.
  • Song show pages will state the instance's name and the names of and links to its artist and genre.

Site Generator

You will need a class whose sole purpose is generating the static pages.

  • It should accept a path upon initialize that indicates where the files it generates will be saved
  • It should use the ERB files from app/views/ to generate all static pages
  • It will live in lib/support

Helpful Rake Tasks

This lab provides you with several Rake tasks to help you along the way.

  • rake db:migrate will automatically create the database and run your migrations; all you need to do is write the migrations
  • rake db:seed will automatically parse the songs and seed your database; no work is required beyond migrations
  • rake console will load a pry session with your environment loaded to play with the database
  • rake generate will run the generate method of your site generator once it is made

active-record-practice-playlister-static-generator-lab's People

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.