1

I have the below line in the user dropdown menu in the header of my app.

<%= link_to "profile (#{user.notifications.count})", current_user %>

This should show profile (3) if the user has three notifications. I want to color the profile a different color from the (3).

Is the best way to do this to give the two different parts different classes? If so, how can I go about doing that?

4

2 回答 2

2

A quick way to accomplish that is to use span, like so

<%= link_to raw("<span style='color: #000'>profile</span> (#{user.notifications.count})"), current_user %>

or if you don't want to insert inline CSS, like so

<%= link_to raw("<span class='your_profile_class'>profile</span> (#{user.notifications.count})"), current_user %>
于 2013-05-07T18:56:05.393 回答
2

You can use a do block:

<%= link_to current_user do %>
  profile (<span class='notifications_count'><%= user.notifications.count %></span>)
<% end %>

This will put a span with html class '.notifications_count' inside the <a></a> tag.

于 2013-05-07T19:02:08.480 回答