I am using Haml in a Ruby on Rails project. I know you use the = sign to execute Ruby, but so far what I have seen is that the Ruby code has to be the last part of a line.
I am trying to add a class to a th element dynamically. (In case it’s relevant: each td also contains more Ruby.)
I have the following code:
%th= link_to 'Name', res_path
I want to add a class to th, and the name of this class is in an instance variable called class_name. I tried this:
%th.=@class_name
But it doesn’t work.
How should one include Ruby code twice on the same line using Haml?
The html_options solution offered by Alok will add the class to the ‘a’ tag. I would do this over two lines instead of one: