I got four different models.
Here's an example,
@single = Single.all
@coe = Coe.all
@blend = Blend.all
@production = @single+@coe+@blend
then how to check which model @production is?
I tried
<% @production.each do |p| %>
<%=p.class.name%>
<% end %>
but it returns "Array"
It seems to be simple, but I can't find out (I edited question)
The problem is here
@single = Single.all
@coe = Coe.all
@blend = Blend.all
@production = @single+@coe+@blend
change these lines with
@single = Single.all.to_a
@coe = Coe.all.to_a
@blend = Blend.all.to_a
@production = @single+@coe+@blend
and then if you will check
@production.first.class.name #Single
@production.last.class.name #Blend
so in your view you can do this
<% @production.each do |p| %>
<% p.each do |product| %>
<%= product.class.name %>
<% end %>
<% end %>
if while iterating on @production it returns array so you need to try this.
<% @production.each do |p| %>
<% p.each do |product| %>
<%= product.class.name %>
<% end %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With