Orsay Orsay - 1 year ago 67
HTML Question

how to had conditionnal class in a method helper?

I'd like to had a conditionnal class in a method helper


def product_icon
elsif product.sent?
'<div class="green-text <%= 'middle' if current_action?(controller: 'products', action: 'index')" %> ><i class="fa fa-envelope-o" aria-hidden="true"></i></div>'.html_safe

But I get this ERROR :

syntax error, unexpected keyword_class, expecting keyword_end
'<div <%= 'class="middle if current_acti...

Any help please ? I can't find the solution

Answer Source

You are in the helper, so you cannot use <%= ... %> but need to use #{....}

Your helper should return this:

return "<div class='green-text <%= 'middle' if current_action?(controller: 'products', action: 'index')'%>><i class='fa fa-envelope-o' aria-hidden='true'></i></div>".html_safe
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download