Story 1 – Add a new team (with name)

Story 1 – Add a new team (with name)

Remember to call our new project football instead of sample

Story 1 – Add a new team (with name)

Task 1 – Create a Model and Database Table for Teams

We are done when this test passes

Do not run ruby script/generate scaffold.

We want to create the model, view, & controller ourselves today!

  1. Add teams table to database
    Create a migration called AddTeams

    1. Edit your migration in the e editor so it creates
      a table called teams with a string column called name
  2. Create a test that asserts we can create a new team called Liverpool (copy the test above)
    1. Run the test with rake test
    2. The test should FAIL
  3. Create a Team model (it should be named Team so it will connect to the teams database)
    1. Run the test with rake test
    2. The test should PASS

Task 2 – Create a controller and view to display all Teams

We are done when http://localhost:3000/teams shows us a page with all our teams

  1. Use ruby script/console to save 2 teams into the database
  2. Create a TeamsController controller (it should be named TeamsController)
  3. What else do you need to do so http://localhost:3000/teams works?

Task 3 – Be able to show a single team

We are done when you can

  • Go to http://localhost:3000/teams
  • Click on a team name
  • See a page that shows that one team

Does it already work?   What errors do you get?

  1. Create a route so the url http://localhost:3000/teams/1 works
    Put the line below near the top of your config/routes.rb file
    map.resources :teams
  2. Create a show action in the controller.  This action should include the line below
    @team = Team.find(params[:id])
  3. Create a show.html.erb view

What do you see when you type rake routes ?

Task 4 – Be able to get to a new team page with a form

We are done when you can

  • Go to http://localhost:3000/teams
  • Click on create new team
  • See a page with a form where you could enter a team name
  1. Add a “Create New Team” link to your index.html.erb form.  Use the link_to helper and make it take you to new_team_path
  2. Add a new action to your controller.  This action should include the line below
    @team = Team.new
  3. Create a new.html.erb view
  4. Test it out (you should see an emptry page now)

Part 2: Create the form

  1. Add this to your new.html.erb

Task 5 – Be able to save our new team

We are done when you can

  • Go to http://localhost:3000/teams
  • Click on create new team
  • Enter a team name & click the Submit button
  • The new team is created and you see it on the list teams page

Click the submit button.  What happens?

  1. Add a create action to your controller with the following code