Rails Zoo

In this project, you will create a new rails application to track the animals in your Rails Zoo!

You will practice the Rails basics in a new context. To keep the requirements manageable, this application will cover only the CR pieces of CRUD. This is an individual Stage 2 project.

Each requirements section of this assignment has three sections: think, create and verify.

  • Use the think section to look up and test your recall on these topics. Each answer is directly relevant to the steps you need to execute in the create section.
  • The create section contains what you would see in a "normal" project's requirements.
  • The verify section contains the steps to verify your work in the create section. This gives you a moment to double check your work before moving on to the next requirement.

Setup

  1. Fork and clone this project
  2. Create a new rails application within this folder using rails new .

Primary Requirements

Create Controller & Model

Think:

  • What Rails CLI command do we use to generate a new controller? Are controllers supposed to be singular or plural?
  • What Rails CLI command do we use to generate a new model? Are models supposed to be singular or plural? Where do we put the fields in the migration?

Create:

  1. a rails controller with the name animals
  2. a new model (migration) with the name animal
    • each animal shall have a name, species and an age (add any other fields you want to track about the animals)
    • i.e. Georgia is a Lion who is 4 years old
  3. create the schema from the migration by running rails db:migrate

Verify:

  1. Check the schema.rb file and ensure all fields you expect are in the animals table
    • if they are not, you may need to create another migration
  2. Run the rails console from the command line and create a few new animals and save them to the database. These animals will be used in the next set of requirements

View All Animals

Think:

  • Which route (including controller#action) do you use for viewing all of a given resource?
  • Which model method do you use to retrieve every item from the database?

Create:

  1. the route
  2. the controller action which will retrieve all animals from the database
  3. the view containing HTML & ERB to see all animal data

Verify:

  1. http://localhost:3000/animals should show a list of all animals in the database that you added in the rails console from the previous section

View One Animal

Think:

  • Which route (including controller#action) do you use for viewing a single resource?
  • Which model method do you use to retrieve a single item from the database?

Create:

  1. the route (including the param)
  2. the controller action which will retrieve one specific animal from the database
  3. the view containing HTML & ERB to see a single animal details
    • you can use lorem pixel to get animal images if you'd like to include a random photo for each animal
  4. add a link to the list of animals which will take you to each animals details page

Verify:

  1. http://localhost:3000/animals will now include links for each animal's detail page
  2. http://localhost:3000/animals/1 should show you the details of one specific animal (assuming you have an animal in the database with an ID of 1)

Create an Animal

Think:

  • Which routes (including controller#action) do you use for creating a new resource? What is the purpose of each route and how do they work together to complete the whole action?
  • Which model methods do you use to create and save a new item to the database?

Create:

  1. the routes
  2. a link on the home page to create a new animal
  3. the controller action for the first route which renders the form
  4. the view to render the form
  5. the controller action for the second route which saves the form database
  6. the special controller method for utilizing strong parameters

Verify:

  1. http://localhost:3000/animals should contain a button to create a new animal
  2. http://localhost:3000/animals/new should show the new animal form
  3. submitting the new animal form should save an animal to the database and show the full list, including the new animal on http://localhost:3000/animals

Optional

  • Complete the edit/update action
  • Complete the delete action
  • Add an image field to the model for an Animal
    • this field will store the location of an image on the internet and be used to display the image on the animal's show page