Ruby on Rails中文处理

说明:Ubuntu Linux操作系统环境为zh_CN.UTF-8,rb程序文件里面需要加入UTF-8 comment,erb 网页程序不需要做处理。


确认系统locale为zh_CN.UTF-8

LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=


编辑vi app/controllers/pages_controller.rb ,并用ghex2软件确认文件编码为UTF-8(参考 Ubuntu上的小工具软件)

需要加入UTF-8 comment

# -*- coding: utf-8 -*-
class PagesController < ApplicationController
  def home
    @title = "Home Chinese中文"
  end

  def contact
    @title = "Contact"
  end

  def about
    @title = "About"
  end

end


编辑vi  app/views/pages/home.html.erb  ,并用ghex2软件确认文件编码为UTF-8(参考 Ubuntu上的小工具软件)

不需要加入UTF-8 comment


参考:Rails 齐步走 http://ihower.tw/rails3/firststep.html


你可能感兴趣的:(Ruby on Rails中文处理)