Zelenka Zelenka - 2 years ago 143
Ruby Question

Escape a single quote sign in highcharts

I'm working on a Rails app and have a serie name "Helen's book" which is shown on the chart as Helen

s book.

I tried to use gsub method in the controller but it didn't work out:

@results[:data].each{|result| x[:result].gsub("'", "\\\\'")}

How to achieve a properly shown single quote sign?

Answer Source

It is 2016. Use UTF-8 proper typographic apostrophe

@results[:data].each do |result|
  x[:result].gsub(/(?<=\W)['"]/, "‘")
            .gsub(/['"](?=\W)/, "’")
            .gsub("'", "’")

#⇒ Helen’s book
#⇒ Book ‘Adventures’
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download