如何在方法助手中有条件 class?
how to had conditional class in a method helper?
我想在方法助手
中有一个条件class
product_helper.rb
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
end
但是我得到这个错误:
syntax error, unexpected keyword_class, expecting keyword_end
'<div <%= 'class="middle if current_acti...
^
你在助手中,所以你不能使用<%= ... %>
但需要使用#{....}
你的助手应该return这个:
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
我想在方法助手
中有一个条件classproduct_helper.rb
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
end
但是我得到这个错误:
syntax error, unexpected keyword_class, expecting keyword_end
'<div <%= 'class="middle if current_acti...
^
你在助手中,所以你不能使用<%= ... %>
但需要使用#{....}
你的助手应该return这个:
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