'Apostrophe Appearing as "'" in Title Tab of Rails App

Apostrophes are appearing as "'" in the title tabs of my Rails application. Everywhere else the apostrophes appear correctly. How may I correct this issue?

Thank you.



Solution 1:[1]

To help those with their "Google Fu".

If you are here because you have are doing the rails title on every page like SO: rails-how-to-change-the-title-of-a-page and have records where your apostrophe is appearing with the &#39 and simply want it with an ' (ie My Dog's Pants instead of My Dog&#39s Pants) then you can checkout this answer that uses ruby string interpolation #{} and .html_safe.

Passing string with apostrophe to helper method doesn't display correctly

As an example, I put a method in my post.rb model:

  def page_title
    "#{ id.to_s +  " - " + name }".html_safe
  end

Then in my posts_controller.rb I have:

@title = @post.page_title

Then in my application.html.erb I have:

<body>
  <title><%= ("Post - " + yield(:title) + " - " unless yield(:title).blank?).to_s + "jaykilleen.com" %></title>
</body>

Then in my show.html.erb for posts I have:

<% content_for :title, @title if @title.present? %>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jay Killeen