Giter VIP home page Giter VIP logo

nyc-sinatra's Introduction

Welcome to NYC Sinatra!

Introduction

We're going to build a history site for New York City, so we're going to need to create the following database structure:

  • You will have three models (and their corresponding tables) Landmark, Title, Figure (think historical figure).

  • A landmark belongs_to a figure and a figure has_many landmarks.

  • Titles and figures have a "many-to-many" relationship, so we'll need a join table.

Domain Model

Our client has decided that the history app we're building them should have a special focus on historical figures. For this reason, it is through figure views and controllers that most of the magic of our app will happen. Our app will have view pages for all of the landmarks and a user will be able to create new landmarks.

However, when a user creates or edits a figure, they should also be able to select or create a new landmark and/or title to associate to that figure. In other words, the form for a new figure and the form to edit a figure should allow the user to select from existing landmarks and title and create new landmarks and titles to associate to the figure. Our client doesn't really care about titles, on the other hand, and we won't be required to build a titles controller or to have any titles views. New titles will only get created in the context of creating or editing a figure.

Instructions

Use the tests to guide you through building your controllers and views.

Migrations

Write migrations to create the following tables:

Figures

id name
1 Robert Moses
2 Al Smith
3 Theodore Roosevelt
4 Peter Stuyvesant
5 Boss Tweed
6 Michael Bloomberg
7 Ed Koch
8 Fiorello LaGuardia
9 Jimmy Walker
10 Belle Moskowitz

Landmarks

id name figure_id year_completed
1 BQE 1 1947
2 Holland Tunnel 5 1927
3 Wall Street Wall 4 1684
4 Brooklyn Battery Tunnel 10 1973

Titles

id name
1 Mayor
2 President
3 Governor
4 NYC Parks commissioner
Join Tables

Any time you have a has_many to has_many relationship, you'll need to create a join table. An example of a has_many to has_many relationship is titles and figures. A title has_many figures because many people hold a title over time and a figure usually has_many titles over their career.

Below is an example of a join table. We called it figure_titles and you should do the same for this lab.

Figure_titles

id title_id figure_id
1 3 2
2 3 3
3 2 3
4 1 9
5 4 1

Models

Now, use the has_many, belongs_to and has_many, :through macros to set up the correct associations in your models:

  • A Landmark belongs_to a figure and a figure has_many landmarks.
  • A title has_many figure_titles and many figures through figure_titles.
  • A figure has_many figure_titles and many titles through figure_titles.
  • A figure_title belongs_to a figure and a title.

Top-Tip: Type tux in your terminal in the directory of this project in order to drop into an interactive Ruby console that is connected to your models and database. Here, you can play around with creating and associating instances of the classes you create once you properly set up the above. This is a helpful way to solidify your understanding of the relationships between your models before you go into building the routes, views and forms that will allows your users to interact with them. Start out by creating a new figure, landmark and title. Then, add that landmark and title to the figures collection of landmarks and titles respectively. Keep playing around from there however you like.

Test Database Migration

Make sure to migrate your test database by running rake db:migrate SINATRA_ENV=test

Seed data

After your Active Record models have been properly defined, you can load the seed data by running rake db:seed.

Views and Controllers

You should create a Landmarks Controller and a Figures Controller. This lab is test-driven; it may be possible to create an app that behaves as expected but will not pass the specific tests. Use these tests to determine how to structure your forms (in particular, the names assigned to specific inputs).

Your forms will need to be complex. Your form for a new figure should dynamically generate checkboxes out of the available landmarks and titles. It should also have fields for creating a new landmark and/or a new title. The controller action that catches the POST request sent by submitting this form should account for this. The same is true of your form for editing a given figure. Read the tests very carefully to understand how you should set up your forms.

Here's a sample form you can use for reference:

sample form

nyc-sinatra's People

Contributors

ahimmelstoss avatar annjohn avatar arelenglish avatar curiositypaths avatar dakotalmartinez avatar danielseehausen avatar deniznida avatar dependabot[bot] avatar fislabstest avatar fs-lms-test-bot avatar hoffm386 avatar ihollander avatar irmiller22 avatar jmburges avatar kthffmn avatar lizbur10 avatar maxwellbenton avatar mendelb avatar pletcher avatar preetness avatar realandrewcohn avatar rishter avatar rrcobb avatar ruchiramani avatar sarogers avatar sgharms avatar shalstein avatar sophiedebenedetto avatar victhevenot avatar vinnyalfieri avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nyc-sinatra's Issues

missing console rake task

we should provide a console rake task so that students can drop into pry console and access/manipulate their models and database tables, to better understand the associations, how to use the code they are building.

Add "Don't forget to run rake db:seed" to instructions.

An instructor and I spent almost an hour trying to figure out why my controller's route's instance variable wasn't showing anything in the view. It would have been nice if the instructions mentioned running rake db:migrate so that the list would be populated, otherwise nothing shows up in the view pages.

Changing a Songs artist Description for Spec is Mis-leading

There is no redirect happening here. If you follow the spec description not the implementation it suggests to use a redirect not a render. In Sinatra there is a difference between redirect and render. Please be more explicit.

    context "changing a song's artist" do

      it "updates the song's artist" do
        fill_in "Artist Name", with: "Some Nobody"
        click_on "Save"

        expect(page).to have_content("Song successfully updated.")
        expect(page).to have_content(song_name)
        expect(page).to have_content("Some Nobody")
      end

      it "redirects to the song show page" do
        fill_in "Artist Name", with: "That singer"
        click_on "Save"
        expect(page.current_path).to eq("/songs/that-one-with-the-guitar")
      end
    end

solution associations wrong and confusing

Why make "Roles" table and not stick with figure titles? Also model associations regarding roles are wrong. Role class says has_many titles and figures. should be belongs to.

Misleading instructions

Inside the instructions for the lab, the lab wants us to create a column for the "Landmarks" table called year_completed. In the instructions, rows for the chart show the year 50 B.C., which would imply there needs the column value needs to be a string, but the test "has a name and a year_completed" is looking for number values. Either the test or that entry on the chart needs to be changed.

no seed data

either add seed data and make clear that students will be writing their own seed file and talk about how to do that.

missing a lot of tests

this repo has one test file, for Landmarks Controller. Missing tests for Figures Controller and Titles Controller. Is this intentional? Older versions of this lab had those files.

Unlimited Beyonce

The Landmarks View Controller Spec doesn't have a .destroy_all for figures, leading to crazy amounts of Beyonce.

[1] pry(#)> Figure.all
=> [#<Figure:0x000000000449fe40 id: 1, name: "Beyonce">,
#<Figure:0x000000000449fcb0 id: 2, name: "Beyonce">,
#<Figure:0x000000000449fb70 id: 3, name: "Beyonce">,
#<Figure:0x000000000449f918 id: 4, name: "Beyonce">,
#<Figure:0x000000000449f788 id: 5, name: "Beyonce">,
#<Figure:0x000000000449f508 id: 6, name: "Beyonce">,
#<Figure:0x000000000449f378 id: 7, name: "Beyonce">,
#<Figure:0x000000000449f1c0 id: 8, name: "Beyonce">,
#<Figure:0x000000000449eea0 id: 9, name: "Beyonce">,
#<Figure:0x000000000449ed38 id: 10, name: "Beyonce">,
#<Figure:0x000000000449ebf8 id: 11, name: "Beyonce">,
#<Figure:0x000000000449ea40 id: 12, name: "Beyonce">,
#<Figure:0x000000000449e8b0 id: 13, name: "Beyonce">,
#<Figure:0x000000000449e770 id: 14, name: "Beyonce">,
#<Figure:0x000000000449e630 id: 15, name: "Beyonce">,
#<Figure:0x000000000449e4a0 id: 16, name: "Beyonce">,
#<Figure:0x000000000449e338 id: 17, name: "Beyonce">,
#<Figure:0x000000000449e158 id: 18, name: "Beyonce">,
#<Figure:0x000000000449dfc8 id: 19, name: "Beyonce">,
#<Figure:0x000000000449de60 id: 20, name: "Beyonce">,
#<Figure:0x000000000449dcd0 id: 21, name: "Beyonce">,
#<Figure:0x000000000449db40 id: 22, name: "Beyonce">,
#<Figure:0x000000000449d910 id: 23, name: "Beyonce">,
#<Figure:0x000000000449d758 id: 24, name: "Beyonce">,
#<Figure:0x000000000449d5f0 id: 25, name: "Beyonce">,
#<Figure:0x000000000449d438 id: 26, name: "Beyonce">,
#<Figure:0x000000000449d2a8 id: 27, name: "Beyonce">,
#<Figure:0x000000000449d0a0 id: 28, name: "Beyonce">,
#<Figure:0x000000000449cec0 id: 29, name: "Beyonce">,
#<Figure:0x000000000449cd30 id: 30, name: "Beyonce">,
#<Figure:0x000000000449cbc8 id: 31, name: "Beyonce">,
#<Figure:0x000000000449ca10 id: 32, name: "Beyonce">,
#<Figure:0x000000000449c858 id: 33, name: "Beyonce">,
#<Figure:0x000000000449c650 id: 34, name: "Beyonce">,
#<Figure:0x000000000449c4c0 id: 35, name: "Beyonce">,
#<Figure:0x000000000449c358 id: 36, name: "Beyonce">,
#<Figure:0x000000000449c1a0 id: 37, name: "Beyonce">,
#<Figure:0x000000000449c010 id: 38, name: "Beyonce">,
#<Figure:0x00000000044a3d88 id: 39, name: "Beyonce">,
#<Figure:0x00000000044a3bf8 id: 40, name: "Beyonce">,
#<Figure:0x00000000044a3a68 id: 41, name: "Beyonce">,
#<Figure:0x00000000044a38d8 id: 42, name: "Beyonce">,
#<Figure:0x00000000044a3748 id: 43, name: "Beyonce">,
#<Figure:0x00000000044a3568 id: 44, name: "Beyonce">,
#<Figure:0x00000000044a3388 id: 45, name: "Beyonce">,

The initial schema state.

In the readme for this lab it states that we should create migrations to match the tables that are displayed. Also in /db/migrate/01_create_landmarks.rb there are instructions to "Write CreateLandmarks migration here"

however

In /db/schema.rb we can see that the landmarks table has already been created prior to the start of the student beginning the lab. Also of note is that the table in schema.rb is not the same as the table represented in the readme . It has datetime columns.

Add Sample New Figure Form

Can we add a screenshot of a working new figure form to the readme to qualify the instructions for students? Something like this:
image

Moving "Join Tables" explanation

It might be helpful to move this explanation of join tables to the previous lab "Sinatra Playlister". The concept is used in both labs, but causes confusion in the previous lab when students are setting up their associations / db (questions were popping up in the "Ask a Question" feature). Then, it is described in detail here (in "Sinatra NYC"), after the student has already struggled through it and no longer needs the help.

Just a thought.

tests use views

The controller tests for this lab should be re-factored to use the view mechanics a bit less.

CC: @aturkewi

Capybara tests

I'm not sure if this is the proper place to do this, but I think the tests on this, and the playlister lab, are too specific. I write my code, get everything to work, and then I have to spend the same, if not more, time changing my code to "fit" the tests. I spend a lot of time just trying to get the tests to pass, even though my code is working fine. I also feel that the tests restrict creativity.

I just wanted to let someone know how.

Misleading information on The Prop being passed

We were passing down the prop as suggested in the reading for the lab but we also needed to pass the pet object as well in order to get the functionality we needed. the state of the data was changing each time we would adopt a pet and then filter through the animals.

difficulty not progressive compared to previous lab

Hi,

I found the lab prior to sinatra NYC (sinatra playlister) to be significantly more difficult due to the addition of the flash and some other items. I would suggest switching the order of the two labs.

controllers sometimes load out of order

add sort to config/environment Dir[File.join(File.dirname(__FILE__), "../app/controllers", "*.rb")].each {|f| require f}, because file order isn't guaranteed and sometimes the application controller is required after the other controller (causing an uninitialized constant error).

fix: Dir[File.join(File.dirname(FILE), "../app/controllers", "*.rb")].sort.each {|f| require f}

solution wrong

a few issues with the solution:

Figure Controller should be Figures Controller, config.ru should reflect this.

Figure Controller missing routes and views for editing and creating figures. There are no tests for this, or for anything Figure-related or Title-related although Readme asks students to build out features for CRUD for each model.

Figures controller solution uses `post` method instead of `patch` for update action

This should be a patch not post -- https://github.com/learn-co-curriculum/nyc-sinatra/blob/solution/app/controllers/figures_controller.rb#L37

The form is making a patch request

Note: In order for it to interpret the patch in the controller, use Rack::MethodOverride needs to be added to the config.ru

Might be worth adding something like this as a resource in the readme: https://stackoverflow.com/questions/5166484/sending-a-delete-request-from-sinatra

@cernanb @ruthmesfun

Spec Directory Order

So in the instructions it's recommended to run rspec ./spec/models/01_thing_spec.rb so you can build things in order. Since RSpec by default will run files\folders in aphabetical order you can prepend numbers to your folders to fix this issue. Then the students just have to run learn or rspec and the tests will happen in order. This lab has no controller tests obviously but I would usually do 01_models, 02_controllers, 03_features since the features are a result of a working model and controller. I'd assume to work with the controller you could use a double or web_mock to insure it's receiving requests and handling them properly in return sending out the expected response.

recommended folder naming convention.

./spec
  /01_models
  /02_features

README/tests mis-match, and folder in wrong place

  • The README mentions checkboxes, but the tests never once check for their presence.
  • The README mentions having only "available" things be listed, but neither explicitly defines that, nor do the tests check for that.
  • The README mentions a JOINS table, but the tests never really check for joins functionality (look through student pull requests to see who actually populates it).
  • The README also says the lab is "test-driven", but you can quite easily get these tests to pass without building much real functionality in, e.g. a test might check for (page.body).to include('figure[name]'), but that spec can easily pass with just a comment, or any text that has that.

The specs/controllers/models folder should be directly under specs.

There are also multiple spelling/grammar typos in the README.

Normally, I would just create a pull request with my suggested changes, but these seem a bit steep for the schedule I'm on.

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.