Jellicle
Jellicle

Reputation: 30216

Rails titleize results in "incompatible encoding regexp match"

My rails app is giving an ActionView::Template::Error with the message:

incompatible encoding regexp match (ISO-8859-1 regexp with UTF-8 string)

The following code triggers this error when the titleize call takes place for the Chinese string 返回. (xxd gives e8bf 94e5 9b9e for these two characters.)

<%= link_to t(:back).titleize, records_path %>

This does not raise an error in my workstation, only on my server.

How can I work around this? What's the cause?

Upvotes: 0

Views: 131

Answers (1)

CamiloVA
CamiloVA

Reputation: 731

I have this problem and to solve this by moment I rewrite titleize method as follow:

app/classes/string.rb

class String

  def titleize
    separator = ' '
    self.strip.split(separator).map do |part|
      part.first.capitalize + part[1..part.size]
    end.join(separator)
  end

end

Upvotes: 1

Related Questions