In my method via some calculations a get data, then i need to view it in view, but if write
@ar.each do |a|
when i have only one record i get error, also when i have one error each is bad idea. So how to do this this?
So i have such code in method:
non_original = []
@articles.each do |a|
non_original << get_non_tecdoc("LA44", 1, "KNECHT")
end
@non_original = non_original
get_non_tecdoc returns object, or nothing…
So in view i have:
-@non_original.each do |no|
=no.brand
=no.description
=no.price
=no.quantity
But what to do if @non_original has one record, then @non_original.each gives error. So how to do check in view? If @non_original has one record, than simple @non_original.brand etc, but if more than one, than use each loop?
This will give you a nice YAML format to look at in your view (assuming ERB).
EDIT: I believe this is what you want, since you’re not interested in debugging.
In your controller, use the splat operator to convert a singleton element to an array (it doesn’t modify arrays):
Then
@ar.eachwill work as expected in your view.Alternatively, you could check in your view: