Show All Narrations for a Narrator
Eventually we’ll have a way to search for Narrator profiles, but we won’t have an index page to show all Narrators. Right now the only way is to navigate from a Narration show page. Currently the Narrator show page works, but we’ll want to list all Narrations from that Narrator. Let’s do that now. We may need a nested resource route. For starters, let’s paste our code from our Narration index page over on the Narrator show page and see what happens, so we’re modifying app/views/narrators/show.html.haml
:
And we get the following error:
NoMethodError in Narrators#show
undefined method `each' for nil:NilClass
So our Narrators#show
action doesn’t have access to the instance variable, @narrations
. Let’s fix that in our narrators_controller.rb
file:
Now the @narrations
instance variable corresponds to this particular narrator’s narrations. Ok, that was relatively painless!