Let's build a rails application!
By the end of this, developers should be able to:
- Follow along in the creation of a rails server.
- Build a complete server side in Rails.
- Create a model with full CRUD capability.
Status checks will be frequent. As developers we want to be meticulous and make sure we're getting errors where expected as we build our server.
This is called "error-driven development". The goal is to see an error, and to learn what error to expect. Embrace the errors, and they will tell you what your next task is.
Follow the steps outlined in good Error Driven Development
- Route
- Test the route, see that a route does not exist
- Add the route
- Test the route, see that a route does exist
- Controller
- Test the route, see that a route does exist but controller does not
- Add the controller
- Test the route, see that a controller exists
- Model
- Test the route, see that a controller exists but model does not
- Add the model
- Test the route, see that a Model exists
- Migrations
- Test the route, see that a Model exists but migrations must be run
- Run migrations
- View
- Test the view, see that it does not exist
- Add the view
- Test Feature
- Test the route, ensure actions are successful
- Use Rails Console to ensure all data persists as expected
- Version 1:
- As a user, I want to view a single book
- As a user, I want to view all books
- As a user, I want to create a book with a title and author
- As a user, I want to edit a book's title and author
- As a user, I want to delete a book
Books | |
---|---|
id | primary key |
title | string |
author | string |
created_at | datetime |
updated_at | datetime |
We'll now go through the steps for completing each CRUD action for multiple resources.
BooksController#index
BooksController#show
BooksController#destroy
BooksController#update
BooksController#create
- Version 1
- As a user, I want to view a single patient
- As a user, I want to view all patients
- As a user, I want to create a patient with a first name, last name, diagnosis and born on
- As a user, I want to edit a patient's first name, last name, diagnosis and born on
- As a user, I want to delete a patient
Patients | |
---|---|
id | primary key |
first_name | string |
last_name | string |
diagnosis | string |
born_on | date |
created_at | datetime |
updated_at | datetime |
Follow the same Error Driven Development steps as you did with books!
PatientsController#index
PatientsController#show
PatientsController#destroy
PatientsController#update
PatientsController#create
- Version 1
- As a user, I want to view a single ingredient
- As a user, I want to view all ingredients
- As a user, I want to create an ingredient with name and unit
- As a user, I want to edit an ingredient's name and unit
- As a user, I want to delete an ingredient
Ingredients | |
---|---|
id | primary key |
name | string |
unit | string |
created_at | datetime |
updated_at | datetime |
IngredientsController#index
IngredientsController#show
IngredientsController#destroy
IngredientsController#update
IngredientsController#create
Developers should run these often!
bin/rake routes
lists the endpoints available in your API.bin/rake test
runs automated tests.bin/rails console
opens a REPL that pre-loads the API.bin/rails db
opens your database client and loads the correct database.bin/rails server
starts the API.