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.
- Fork and clone this project
- Create a new rails application within this folder using
rails new .
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:
- a rails controller with the name
animals
- a new model (migration) with the name
animal
- each animal shall have a
name
,species
and anage
(add any other fields you want to track about the animals) - i.e. Georgia is a Lion who is 4 years old
- each animal shall have a
- create the schema from the migration by running
rails db:migrate
Verify:
- 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
- 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
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:
- the route
- the controller action which will retrieve all animals from the database
- the view containing HTML & ERB to see all animal data
Verify:
- 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
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:
- the route (including the param)
- the controller action which will retrieve one specific animal from the database
- 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
- add a link to the list of animals which will take you to each animals details page
Verify:
- http://localhost:3000/animals will now include links for each animal's detail page
- 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)
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:
- the routes
- a link on the home page to create a new animal
- the controller action for the first route which renders the form
- the view to render the form
- the controller action for the second route which saves the form database
- the special controller method for utilizing strong parameters
Verify:
- http://localhost:3000/animals should contain a button to create a new animal
- http://localhost:3000/animals/new should show the new animal form
- 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
- 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