Help Frog Rancher Darryl categorize and track all the ponds, frogs, and tadpoles on his ranch. To do this you will create migrations and models complete with ActiveRecord associations.
After speaking with Darryl, he has informed us that he has several ponds on his ranch. Each pond has different frogs that live there. Some of those frogs have tadpole babies. The frogs all have the ability to have tadpoles at any given time and the tadpoles have the ability to metamorphosize into frogs at any time.
-
Run
bundle install
thenrspec
to see what course to take. Keep in mind that for the association of tadpoles belonging to a pond through frog, you'll have to delegate. -
Take a look at the tests in
spec/models
before writing your migrations. -
Once your migrations are done, start on the associations in your models.
-
Once the associations are passing, you'll be modifying three files:
- app/controllers/tadpoles_controller.rb
- You'll add an action,
#metamorphoize
, to this controller
- config/routes.rb
- Here you'll allow a form to post to /tadpoles/:id/metamorphosize
- This should route the request to the Tadpoles Controller's metamorphoize action
- views/tadpoles/show.html.erb
- You'll add a form that will post to
/tadpoles/:id/metamorphosize
with a submit button that reads "Become a frog"
-
If you get stuck refer to Rails Active Record Documentation.
-
You can refer to this link as a quick reference for the Rails 4 folder structure along the way here.
- When you're finished and all the specs are passing, go ahead and run the following commands from your terminal:
- rake db:migrate
- rake db:seed
- rails s
- Then hit up the app here.
- Think about how you would get a tadpole to metamorphosize. Click on any tadpole and make it metamorphosize. Did the app go about metamorphosizing tadpoles in the same way you would have?
- Think about how you would get a frog to have tadpole babies. Click on any frog and make it have a baby. Did the app go about making baby tadpoles in the same way you would have? For more details about metamorphosize into a frog, see
config/routes.rb
andviews/frogs/show.html.erb
. You can learn more about nested resources below.