[I’ve no idea how this got into the ‘test’ section so sorry for the
duplicate!]
I have a list of scripts, that when one is clicked on displays a new
page with relating runs for that script.
I would like to include an if/else statement so that when the number of
runs for a script is zero, the resulting page displays ‘no runs found’.
The runs display uses a <% for run in @runs %> loop to display a rows of
run details, immediately after which I have placed <% if (@runs.size ==
0) %> - however, the ‘else’ part of the statement is still run even when
no rows are found.
run details, immediately after which I have placed <% if
(@runs.size ==
0) %> - however, the ‘else’ part of the statement is still run even
when
no rows are found.
What am I doing wrong?
Well, for starters, not showing enough of your code, but I’ll take a
shot anyway.
<% if @runs.blank? -%>
No rows found
<% else -%>
<% for run in @runs -%>
<%= row_for(run) %>
<% end -%>
<% end -%>
Since .blank? works with nil, it avoids possible issues with nil.size
== 0 (which is better expressed as @runs.empty? anyway).