関連のない 2 つのテーブルがあり、それらを同時にループして、それぞれの異なる属性を呼び出す必要があります。したがって、現時点では(簡単にするために一般的な名前を使用しています):
<% @combined = Tableone.all + Tabletwo.all %>
<% @combined.each do |c| %>
<% if c.is_a?(Tableone) %>
do some code....
<% elsif c.is_a?(Tabletwo) %>
do other code...
<% end %>
<% end %>
そのため、現時点では elsif ブロックに到達しておらず、Tableone の結果のみが表示されています。これを回避して両方のテーブルをループするにはどうすればよいですか?
編集: これが完全なコードです。
<% @subcategory = Subcategory.all %>
<% @product = Product.all %>
<% @ps = Product.all + Subcategory.all %>
<% @ps.each do |ps| %>
<% if (ps).is_a?(Product) %>
<% if (ps).display_on_home_page and !(ps).is_highlight_product and !(ps == '..') %>
<% if ps.price_from %>
<div class="column_entry">
<div class="product_special">
<span class="a">From Only</span>
<span class="b"><%= number_to_currency(ps.price,:unit=>'€') %></span></div>
<%= link_to image_tag(ps.product_image.url(:normal_page_size)), products_content_url(ps.id), :controller=>'products' %>
</div>
<% else %>
<div class="column_entry">
<div class="product_special">
<span class="a">Only</span>
<span class="b"><%= number_to_currency(ps.price,:unit=>'€') %></span>
</div>
<%= link_to image_tag(ps.product_image.url(:normal_page_size)), products_content_url(ps.id), :controller=>'products' %>
</div>
<% end %>
<% elsif (ps).is_a?(Subcategory) %>
<%= "Reached elsif" %>
<% if (ps).display_on_home_page and !(ps).is_highlight_product and !(ps == '..') %>
<div class="column_entry">
<%= link_to image_tag(ps.image_attachment.url(:normal_page_size)), subcategories_content_url(ps.id), :controller=>'subcategories' %>
</div>
<% end %>
<% end %>
<% end %>
<% end %>