How do I use an if statement in HAML to manipulate a tag class string?
I have a condition where if action_name contains "index" then the second class should only return "index", otherwise set it to action_name.
I tried something like this:
- if action_name =~ /.*index.*/
%body{ :class => "#{controller_name} index" }
- else
%body{ :class => "#{controller_name} #{action_name}" }
Unfortunately, I left the rest of my body in the layout that follows them and it shows up for suggestion only else
.
I suppose there is a more readable one liner I could use here, and also if it was doing an if inside a line versus a more verbose multi-line if statement, but I could use some help here to get that to work as expected in HAML.
+3
source to share