sparkle
sparkle

Reputation: 7390

Run a block if a condition pass

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.

Upvotes: 0

Views: 187

Answers (1)

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33420

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

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

Upvotes: 1

Related Questions