<%unless (@students.empty? and params[:commit].nil?) %>
<%="test"%>
<%= render :partial => 'results' %>
<% end %>
Even though in some cases @students.empty? returns false and params
[:commit].nil? returns true (or the opposite), it displays the test
and the render area.
I put before and after the code the <%=params[:commit].nil?%> and <
%=@students.empty?%> so I can see it (it shows false and true or the
opposite and always it shows the render area and the test). I also
tried && but it was the same problem.
I think you have some misunderstanding when it comes to boolean logic
- Your code that works is just fundamentally different to the first
snippet you showed.
unless a
unless b
...
end
end
is equivalent to if !a && !b
but
unless a && b
...
end
is equivalent to if !( a && b) which in turn is equivalent to !a || !
b (see de morgan's laws)
puts "Render" unless(true && false) # Prints Render
puts "Render" unless(true || false) # Does not print
puts "Render" unless(false || true) # Does not print
puts "Render" unless(true || true) # Does not print
puts "Render" unless(false || false) # Prints render (which is what
you want)
I think Jeffrey is right, "unless" with complex logic is just too
difficult for most of us to get our brains round easily. I avoid it
except in trivially simple cases.
Maybe I should not have said 'most of us' but certainly it applies to
me. There is a similar problem with variables with names like
not_valid, it is too easy to overload the brain when included in a
logical expression.