rico_mac
rico_mac

Reputation: 888

adding a class to text displayed by rails in the view

very straight forward..

how do I add a class to something like this

<h2><%= guide.title %></h2>

which is just displaying text?

Upvotes: 1

Views: 301

Answers (1)

BroiSatse
BroiSatse

Reputation: 44675

You have to wrap it within some container:

<div class="my_class"><%= guide.title %></div>

The container you'll use depends on the context given text is to be used.

Update:

Since the text is already wrapped in <h2> you can do:

<h2 class='my_class'><%= guide.title %></h2>

Another update:

If you wan to minimize the amount of pure html in your view, you can always do:

<%= content_tag :h2, class: 'my_class' do %>
  <%= guide.title %>
<% end %>  

Upvotes: 5

Related Questions