Search code examples
rubyhaml

how to add a class to a conditional in HAML


Ok, I have this line in my file which is in HAML

- unless @place.blank?

I need to add a class to it, regardless of the condition.

I've tried doing this:

- {:class => ("extra_middle" unless place.blank?)}

That doesn't work. I've tried other variations to no avail.

EDIT

Please keep in mind that there is a dash which in HAML means do not render unless not blank, right?

EDIT 2

To explain a bit more, the class I'm trying to add is meant to hide that specific part unless someone clicks on a link which will then show it ...

So, the class is regardless of result of place being blank or not ...


Solution

  • Call me stupid here, but could you not just put the -unless place.blank? inside a div

     .extra_middle
        -unless place.blank?
          .Whatever else you need