I have the following code in Ruby on Rails 3. What is the preferred way to set the class (or id) to the value of a variable, and output it?
<%= tag "td", :class => @priority_level %><%= @priority_level %></td>
Outputs:
<td class="normal">normal</td>
Thanks.
The content_tag helper is sometimes visually more appealing than intermixing Erb and HTML:
There are also other templating options out there besides the default Erb.
Here’s the equivalent in Haml :
and Mustache:
I think that both are easier on the eyes than Erb. If you’re stuck in Erb-land, organizing your code into helper methods and partials as much as possible is a good way to keep Erb templates visually manageable.