Associations and Nested Routes Flashcards
When creating a model for a specific model that belongs to another model, what command can you run?
rails generate model Bone dinosaur:belongs_to
Write the list of Active Record Associations List Methods
- has_one
- belongs_to
- has_many
has_one :through
has_many :through
Write an example for a model named Bone and a model named Dinosaur, what to include inside the model of each. Where the Bone belongs to the Dinosaur. In your terminal what association method could you write to see what bones a dinosaur has?
Bone Model File:
belongs_to :dinosaur
Dinosaur Model File:
has_many :bones
dinosaur.bones
Write an example of a Nested Resource where the Bone Model belongs to the Dinosaur.
resources :dinosaur, only[:new, :show] do
resources :bones, only[:new]
end
What would the following nested resource
resources :dinosaurs, only [:index, :show] do
resources :bones, only [:show] do
end
get /dinosaurs/dinosaur_id/bone_id