Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional CSS in Ruby and Haml Table

Tags:

css

ruby

haml

I have a list of items in a table. Some are true and some are false. Is there a way that the true elements can have one background colour whilst the false elements have another. I was considering writing a method in the application helper but I am not sure how is best to write this. So far all i have is

%td.success= person.success

This currently prints out true or false to the table but i would just like to add some background colour to this?

like image 934
Lilp Avatar asked Jun 27 '26 00:06

Lilp


1 Answers

Or why not something like this:

css

td.success { background-color: 'green' }
td.failure { background-color: 'red' }

then in the haml

%td{class: "#{person.success ? 'success' : 'failure'}"} = person.success

Or

- if person.success
  %td.success = person.success
- else
  %td.failure = person.success
like image 50
engineersmnky Avatar answered Jun 28 '26 17:06

engineersmnky