Associations and Nested Routes Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

When creating a model for a specific model that belongs to another model, what command can you run?

A

rails generate model Bone dinosaur:belongs_to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write the list of Active Record Associations List Methods

A
  • has_one
  • belongs_to
  • has_many
    has_one :through
    has_many :through
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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?

A

Bone Model File:
belongs_to :dinosaur

Dinosaur Model File:
has_many :bones

dinosaur.bones

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write an example of a Nested Resource where the Bone Model belongs to the Dinosaur.

A

resources :dinosaur, only[:new, :show] do
resources :bones, only[:new]
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What would the following nested resource
resources :dinosaurs, only [:index, :show] do
resources :bones, only [:show] do
end

A

get /dinosaurs/dinosaur_id/bone_id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly