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!
- Add teams table to database
Create a migration called AddTeams- Edit your migration in the e editor so it creates
a table called teams with a string column called name
- Edit your migration in the e editor so it creates
- Create a test that asserts we can create a new team called Liverpool (copy the test above)
- Run the test with rake test
- The test should FAIL
- Create a Team model (it should be named Team so it will connect to the teams database)
- Run the test with rake test
- 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
- Use ruby script/console to save 2 teams into the database
- Create a TeamsController controller (it should be named TeamsController)
- 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?
- 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 - Create a show action in the controller. This action should include the line below
@team = Team.find(params[:id]) - 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
- 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
- Add a new action to your controller. This action should include the line below
@team = Team.new - Create a new.html.erb view
- Test it out (you should see an emptry page now)
Part 2: Create the form
- 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?
- Add a create action to your controller with the following code