Customer Sign In 1-888-250-8971
  • Products
  • Solutions
  • Pricing
  • Why Samanage
  • Company
Start Free Trial

Products

Service management solutions that grow and evolve with your business.

5 Benefits to IT Service Management

Samanage Service Platform

The smartest employee service management platform to run your service business.

Features

  • Incident Management
  • Service Portal
  • Change Management
  • Service Catalog
  • IT Asset Management
  • Knowledge Base
  • Problem Management
  • Reporting
  • SEE ALL FEATURES arrow-icn

Platform

  • Automations
  • Mobile
  • Internationalization
  • API
  • Documentation

Integrations

  • Google Apps
  • Slack
  • Jira
  • Zendesk
  • Zapier
  • Salesforce
  • SEE ALL INTEGRATIONS arrow-icn

Samanage for Salesforce

Extend your Salesforce Service Cloud investment with Employee Services

Samanage for Salesforce is built on on the Salesforce Service Cloud and provides customers a way to manage employee and customer service operations in an integrated way...

Learn more about Samanage for Salesforce.

Solutions

Best practices and solutions to meet your service needs.

Raising the Bar

IT Management

  • ITSM
  • ITIL
  • Computer Inventory
  • IT Service Desk
  • Microsoft Audit
  • IT Audit

Department

  • IT
  • Human Resources
  • Facilities Management

Industry

  • Financial Services
  • Healthcare

Why Samanage

We listen closely and quickly align solutions accordingly.

Demo

Our Customers

  • Awards
  • Reviews
  • Case Studies
  • Compare Service Desks

Our Commitment

  • Customer Service & Support
  • Community

Our Insights

  • Blog
  • White Papers
  • Datasheets
  • Webinars
  • Videos
  • Infographics

Company

Our leadership and team bring a fresh vision to the service industry.

How IT Plays a Lead Role

Who We Are

  • About Us
  • Leadership
  • Meet The Team
  • Investors
  • Partners

What We're Up To

  • Careers
  • News
  • Events
  • Contact
  • Products

    Samanage Service Platform

    The smartest employee service management platform to run your service business.

    Features
    • Incident Management
    • Service Portal
    • Change Management
    • Service Catalog
    • IT Asset Management
    • Knowledge Base
    • Problem Management
    • Reporting
    SEE ALL FEATURES arrow-icn
    Platform
    • Automations
    • Mobile
    • Internationalization
    • API
    • Documentation
    Integrations
    • Google Apps
    • Slack
    • Jira
    • Zendesk
    • Zapier
    • Salesforce
    SEE ALL INTEGRATIONS arrow-icn

    Running your enterprise on Salesforce?

    Try Samanage for Salesforce
  • Solutions
    IT Management
    • ITSM
    • ITIL
    • Computer Inventory
    • IT Service Desk
    • Microsoft Audit
    • IT Audit
    Department
    • IT
    • Human Resources
    • Facilities Management
    Industry
    • Financial Services
    • Healthcare
    • Education
  • Pricing
  • Why Samanage
    Our Customers
    • Awards
    • Reviews
    • Case Studies
    • Compare Service Desks
    Our Commitment
    • Customer Service & Support
    • Community
    Our Insights
    • Blog
    • White Papers
    • Datasheets
    • Webinars
    • Videos
    • Infographics
  • Company
    Who We Are
    • About Us
    • Leadership
    • Meet The Team
    • Investors
    • Partners
    What We're Up To
    • Careers
    • News
    • Events
    • Contact
Start Free Trial

Insights

Tales from upgrading to Ruby 1.9.2 – character encoding

Written by Nir Tzur on September 18, 2011 at 9:40 am

  • Tweet
  • Share 0
  • LinkedIn 0
Official Ruby logo

Image via Wikipedia

In an effort to contribue some of the engineering knowledge back to the community, this is the first post with a more engineering/technical focus from our VP of engineering, Nir Tzur.

In an ongoing effort to improve application performance we have recently made it a high priority to upgrade our rails (2.3.14) environment from Ruby 1.8.7 to release 1.9.2. We have briefly considered a move to Ruby Enterprise Edition (REE), but decided against it as the internal improvements with 1.9.2 are expected to be superior, and frankly put, we’re not sure about REE’s future.

Well, I have much to say in favor of Rails and Ruby, but someone had to stop me from “praising” 1.9.2 Encoding during this upgrade. There are tons of blogs and articles over the net discussing this issue, but apparently none of them covered all that we needed. So, I thought it would be a good idea to list what we’ve had to do, hoping that it will help someone, somewhere, sometime.

The first thing we’ve done was to find sources with non-ASCII characters and insert the utf-8 magic comment on their first line. These sources were mostly related to string analysis methods involving gsub functionality. For the sake of web searches, here is the comment we use:

# -*- encoding: utf-8 -*-

We are using mysql2, so we were lucky enough to skip the need to use mysql patches to support utf-8 encoding.

Then, we set Encoding.default_external and Encoding.default_internal to Encoding::UTF_8 in our environment.rb. We have done that early enough such that it gets invoked before our boot.rb gets loaded.

That was clearly not enough. We found out that utf-8 encoded strings that were posted to our controllers, were actually set as ASCII. To fix that we had to install a the following monkeypatch, also listed below:

# Patching ActionController:
#
module ActionController

  class Request
    private
    def normalize_parameters_with_force_encoding(value)
      (_value = normalize_parameters_without_force_encoding(value)).respond_to?(:force_encoding) ?
         _value.force_encoding(Encoding::UTF_8) : _value
    end
    alias_method_chain :normalize_parameters, :force_encoding
  end
end

In addition, we had to set the Encoding.locale_charmap to utf-8 as well. Before discussing this deeply, I’d like to point you out to this wonderful post that directed us to make this change. To set the Encoding.locale_charmap, we had to set the ENV[‘LANG’] environment variable before starting rails. This should be easily done setting LANG=en_US.UTF-8 on /etc/profile, which can be viewed using Unix’s `locale` command.

Well, it didn’t work, so we tried setting it on /etc/environment, but it didn’t work either. It took us time to understand that our passenger (3.0.8) and nginx are blocking environment variables from being passed to Ruby. We ended up with wrapping the ruby invokation in passenger as follows:

#!/bin/sh
export LANG=en_US.utf8;
exec “/usr/bin/ruby” “$@”

That was almost it!

To finalize our actions, we had to:

  1. Set the same environment variables on all our servers, such that rake invokation will work well with utf-8 strings.
  2. Use force_encoding(‘utf-8′) in some specific areas, for example, we use net/imap to retrieve e-mails, and had to use .toutf8 method on messages’ subject. For some reason, the string representation of messages’ body worked well without our interfering.
  3. Replace ‘render :inline’ of mixed ASCII and utf-8 strings, with a ‘render :partial => …’ which did the same functionality.

So, I hope this info will serve you and save you the countless hours we spent on encoding while upgrading to 1.9.2.

Nir

Tales from upgrading to Ruby 1.9.2 – character encoding Click To Tweet
  • Tweet
  • Share 0
  • LinkedIn 0

Tags:

Enterprise IT Software

Related Posts

  • Where Does Samanage Fit into the History of Software?
  • Friday Fun: The 5 Stupidest Uses for Smart Technology
  • Secure IT Asset Disposal and Where Compliance Falls Short
  • Friday Fun: The IT Service Desk Staffed By Guardians of the Galaxy Characters
  • Friday Fun: 8 Google Autocompletes That Can Brighten a Tough Day at Work
Subscribe to our Blog
  • Blog Home
  • IT Asset Management
  • IT Service Management
  • Enterprise Service Management
  • Help Desk Software
  • Cloud
  • Company
  • Friday Fun
  • Insights

Register Here:

How to Increase Employee Productivity
Products
  • Samanage Service Platform
  • Samanage for Salesforce®
Resources
  • Blog
  • Community
  • Webinars
  • White Papers
  • Datasheets
  • FAQ
  • API Documentation
Company
  • About Us
  • Leadership
  • Investors
  • Careers
  • News
  • Partners
  • Events
  • Contact
Contact Us
  • Samanage North America
    117 Edinburgh South,
    Suite 100
    Cary, NC, USA 27511
    1-888-250-8971

    San-Francisco address
    535 Mission St,
    14th floor
    San Francisco, CA 94105

  • Samanage Australia
    300b Glenmore Rd,
    Paddington NSW 2021,
    Australia
    +61-2-8319-5874
  • Samanage Europe B.V.
    Westblaak 180
    3012 KN Rotterdam, NL
    +31-10-8920398


    United Kingdom Office
    1 Fore St,
    6th floor
    London EC2Y 9DT, UK
    +44-20-3868-1381
  • Israel
    P.O box 8733
    5 Ha Melacha St.
    Netanya 4250540

© 2019 Samanage Ltd. All rights reserved. | Terms | Privacy | Sitemap

X
Don't take our word for it!
Check out real service desk vendor reviews from G2 Crowd
  • This field is for validation purposes and should be left unchanged.
6 ways to close tickets faster (without even looking at them)
  • This field is for validation purposes and should be left unchanged.
Whitepaper