Using rails, how can I loop through an array defined in my controller, create a partial for each item, and access each item's value in the partial?
The Controller
Define an array for my "grapher" page:
class StaticPagesController < ApplicationController
def home
end
def grapher
@available_graphs = ["pie.png", "line.png", "lineplusbar.png"]
end
end
The page View
In my grapher.html.erb view, I want to loop through my array and create a partial for each item.
<%= render :partial => 'graphPreviewItem', :collection => @available_graphs %>
The partial View
How can I access the array item inside of the partial?
<div class="thumbnailContainer">
<a class="thumbnail" href="#">
<%= image_tag "this should be the array item value" %>
</a>
</div>