Suppose my array looks like this:
People => [
{
Person => Jack,
Age => 25
},
{
Person => Frank,
Age => 45
},
{
Person => Molly,
Age => 30
}
]
I thought that iteration code would be in the controller since it is handling data. My controller code looks like this:
class People < ApplicationController
def list
people.each do |hash|
@person = hash[person]
@age = hash[age]
end
end
end
My view code looks like:
<h1>People</h1>
<p>
Person: <%= @person %> <br/>
Age: <%= @age %> <br/>
<br/>
</p>
When I load the page, rather than seeing three blocks of output, one for each person, I only see one block for Molly: the last iteration.
I'm thinking I need to put the iteration code in the view rather than the controller. Is this correct?