I am building a sample site to familiarize myself with RoR. I followed the book "Agile Web Development with Rails" up to a point, and now I am experimenting and using it as a reference, however I haven't been able to find the answer to my problem.
I have two models of interest, one is supermarketchain and the other supermarket. Obviously, a supermarket chain has a bunch of supermarkets. What I am trying to do is get the basic "show" page for a single supermarket chain to display a list of the supermarkets that belong to it.
I also didn't want to repeat myself (because apparently it's a Very Bad Thing), and so I thought I could use "render" to insert supermarket's index.html.erb into the supermarketchain/show.html.erb page, like this:
<%= render :template => 'supermarkets/index' %>
However, that produced zero output on the page.
My next approach was to make this partial:
<div id="supermarket-list">
<h1><%= I18n.t "supermarket.title" %></h1>
<table>
<% for s in @supermarkets %>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<td>
<%= s.supermarketchain.name %>
</td>
<td>
<%= s.address %>
</td>
<td class="list-actions">
<%= link_to I18n.t("general.show"), s%> <br/>
<%= link_to I18n.t("general.edit"), edit_supermarket_path(s) %> <br />
<%= link_to I18n.t("general.delete"), s, :confirm => I18n.t("general.confirmation"), :method => :delete %>
</td>
</tr>
<%end%>
</table>
</div>
And then use:
<% @supermarkets = Supermarket.all %>
<%= render :partial => 'supermarkets/supermarket' %>
To insert it on the supermarketchain's show page.
What I am wondering is whether this is a good practice. It seems to me weird to initialize a variable for use by a partial, when what I want displayed is the exact result of the "index" action of the supermarkets controller. Comments?
Please ask for any needed clarifications.