Running with Ruby

Tag: Ruby 1.8.7 (page 2 of 14)

Ruby on Rails on Passenger and Redmine: incompatible character encodings: UTF-8 and ASCII-8BIT

After migrating Redmine to a new server, I’ve encountered such an error:

ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT):
    3: <div class="box tabular settings">
    4: <p><%= setting_select :ui_theme, Redmine::Themes.themes.collect {|t| [,]}, :blank => :label_default, :label => :label_theme %></p>
    6: <p><%= setting_select :default_language, lang_options_for_select(false) %></p>
    8: <p><%= setting_select :start_of_week, [[day_name(1),'1'], [day_name(6),'6'], [day_name(7),'7']], :blank => :label_language_based %></p>
    9: <% locale = User.current.language.blank? ? ::I18n.locale : User.current.language %>
  app/helpers/settings_helper.rb:40:in `setting_select'
  app/views/settings/_display.html.erb:6:in `block in _app_views_settings__display_html_erb__83012438_101817890'
  app/views/settings/_display.html.erb:1:in `_app_views_settings__display_html_erb__83012438_101817890'
  app/views/common/_tabs.html.erb:24:in `block in _app_views_common__tabs_html_erb__985403460_101198110'
  app/views/common/_tabs.html.erb:23:in `each'
  app/views/common/_tabs.html.erb:23:in `_app_views_common__tabs_html_erb__985403460_101198110'
  app/helpers/application_helper.rb:263:in `render_tabs'
  app/views/settings/edit.html.erb:3:in `_app_views_settings_edit_html_erb__815292708_88944890'
  app/controllers/settings_controller.rb:26:in `index'

My database and all my configs were set to UTF8, so it looked like the problem was somewhere in Apache. Partialy I was right. To fix this issue, you need to add following lines:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

to /etc/apache2/envvars and then just restart server:

# /etc/apache2/envvars
/etc/init.d/apache2 restart

Ruby Geokit invalid trailing UTF-8 octet at line 1 column 1 fix

Today I’ve encountered a small problem with Geokit:

Psych::SyntaxError: (<unknown>): invalid trailing UTF-8 octet at line 1 column 1

I don’t have time (because it happened on production) to investigate this issue, so I’ve developed a quick temporary fix, which just removes invalid characters:

# Temporary workaround for crazy not UTF-8 characters in response
module Geokit
  module Geocoders
    class IpGeocoder
      require 'iconv'

      def self.parse_body(body)
        yaml = YAML.load(Iconv.conv('ASCII//IGNORE', 'UTF8', body))
        res =
        res.provider = 'hostip', res.state = yaml['City'].split(', ')
        country, res.country_code = yaml['Country'].split(' (') = yaml['Latitude']
        res.lng = yaml['Longitude']
        res.success = !( =~ /\(.+\)/)
Olderposts Newerposts

Copyright © 2017 Running with Ruby

Theme by Anders NorenUp ↑