I have a relatively simple question. I have a line of code like this:
content_tag(:span, some_variable, { :class => span_class })
but if the variable span_class is nil, this outputs <span class>some_variable</span>.
I want the hash to only occur under some condition. Is there a way to do something like this:
content_tag(:span, some_variable, { :class => span_class } if some_condition)
Thanks.
I’m surprised that it’s doing what you say, I would expect:
to not return a class if
span_classis nil. However, I think you could get back to valid markup by just passing||'', like so: