I’d like to show a specific image on the first iteration when the partial template is called, but not the rest:
view file:
<% @categories.each do |category,i,category_locales| %>
<div class="featured_deals">
<%= render :partial => "medium_deal", :collection => category_locales, :as => :deal_locale %>
</div>
<% end %>
medium_deal file:
<% deal = deal_locale.deal %>
<%= image_tag 'layout/featured_deal_left_blue.png', :style => 'float: left; padding-top: 11px;' %>
# I only want this image to show for the FIRST element of category_locales, but not the rest.
<div class="featured_deal_wrapper">
Hello
</div>
I tried passing a counter in the first view file, but it is not incremented until the “each” passes through again.
You should be able to do this:
See: http://guides.rubyonrails.org/layouts_and_rendering.html#local-variables