Run a block if a condition pass

169 Views Asked by At

I want to run this block only a condition is satisfied

<% if condition %>
 <% progressive_render do %>
   SLOW CODE HERE
 <% end %>
<% end %>

IF condition = true

SLOW CODE should be runnned wrapped by "progressive_render"

IF condition = true

SLOW CODE shoud be runned not wrapped by progressive_render. So runned anyway.

1

There are 1 best solutions below

0
On BEST ANSWER

You can replace the if-else condition with a guard clause (plus unless condition):

<% SLOW CODE HERE unless condition %>
<% progressive_render { SLOW CODE HERE } %>