Giter Site home page Giter Site logo

playlister-static-generator-with-ar-web-100817'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

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 and ActiveRecord macros, special methods created by ActiveRecord's DSL.

The model tests will be calling methods that your models will, by default, have if your associations are correctly defined. You do not need to write those methods. Once your associations are defined you 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

You processed files will be in the following structure:

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

Index Pages

Each model will generally have an index page. Often they list all instances of model

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

Show Pages

An instance of a model will often have show.html.erb that is rendered as a regular HTML file with information specific to that instance.

  • Each model will have show pages in app/views/<model>/
  • Artist show pages will have the instance's name and a list of and link to its genres and songs.
  • Genre show pages will have have the instance's name and a list of and link to its artists and songs.
  • Song show pages will state the instance's name and 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 to where it will save the files it generates
  • 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 a number of Rake tasks to help you along the way.

  • rake db:migrate will automatically create 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 required beyond migrations
  • rake console will load a pry session with all of your environment loaded to play with the database
  • rake generate will run your site generator once it is made assuming it has generate method

View Static Playlister on ActiveRecord on Learn.co and start learning to code for free.

playlister-static-generator-with-ar-web-100817's People

Contributors

tsiege avatar loganhasson avatar pletcher avatar aviflombaum avatar kthffmn avatar irmiller22 avatar fislabstest avatar fs-lms-test-bot avatar sarogers avatar octosteve avatar ahimmelstoss avatar babyshoes avatar changamanda 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.