Reputation: 3052
<%= link_to 'Received Messages<span class="badge badge info">
@receivedmessage.count</span>'.html_safe, '/messages/show' %>
below is the output i'm getting so far. I have to get the "message count number" inside the badge instead of "@receivedmessage.count"
Upvotes: 0
Views: 409
Reputation: 1223
When you want to interpolate your variable you should use quotes instead of single quotes. Also, you'll need to use #{}
around your variable. An example:
name = 'John'
puts "Hello, #{name}!"
Notice how I've used quotes on the second line when using string interpolation and surrounded the variable name
with #{}
?
Now, let's apply it to your example:
<%= link_to "Received Messages <span class='badge badge info'>#{@receivedmessage.count}</span>".html_safe, '/messages/show' %>
Update
String interpolation and html_safe
might not always be a good idea, but since your only interpolating a count
it should be fine. A better option would be to use what Micha has suggested (using link_to ... do
):
<%= link_to '/messages/show' do %>
Received Messages <span class="badge badge info"><%= @receivedmessage.count %></span>
<% end %>
Upvotes: 0
Reputation: 43298
You can use link_to ... do
, which IMO is cleaner than newmediafreak's answer:
<%= link_to '/messages/show' do %>
Received Messages<span class="badge badge info"><%= @receivedmessage.count %></span>
<% end %>
Upvotes: 3