3

I need to add a dynamic class to some regular classes while updating syntax for Hyperstack:

div.upload_header.text_left(class: ('uploaded' if 
FileUploads.complete?)) do

Should become something like this:

DIV(class: 'upload-header text-left (dynamic 'uploaded' should go 
here)') do

I just can't seem to figure out how/if regular and dynamic classes can be declared together.

  • Welcome to Stack Overflow. You need to add some precision to your question. What is your problem, what have you tried and what is your question. Please see: [How to ask](https://stackoverflow.com/help/how-to-ask) – probitaille Mar 27 '19 at 20:49
  • FYI matt the old haml style (i.e. `div.upload_header`) is deprecated so you want to get rid of that stuff anyway. – Mitch VanDuyn Mar 28 '19 at 14:56

1 Answers1

4

String interpolation can be done conditionally:

DIV(class: "upload-header text-left #{'uploaded' if FileUploads.complete?}")

The class parameter can also accept an array:

def upload_header_classes
  ['upload-header', 'text-left'].tap do |classes|
    classes << 'uploaded' if FileUploads.complete?
  end
end

DIV(class: upload_header_classes)

I'm sure there are plenty of other ways to do it too, this is ruby!