ruby on rails - Multiple Conditional Classes in HAML -
using ruby , haml, there shorter way represent logic:
%tr{class: "#{'success' if admin.approved?} #{'warning' unless admin.approved?}"}
thanks!
you can simplify logic using ternary statement (one line if/else):
%tr{class: admin.approved? ? 'success' : 'warning'}
or move logic helper. example, create helper method in application_helper.rb
:
def admin_row_class(admin) admin.approved? ? 'success' : 'warning' end
then use helper in view:
%tr{class: admin_row_class(admin)}