ROR支持中文配置

ruby on rails 安装及中文配置

1.install ruby for windows.
http://rubyinstaller.rubyforge.org/ 下载“One-Click Ruby Installer”安装Ruby、RubyGems。
2.install rails .
path/to/ruby/bin> gem install rails
默认是远程安装。根据提示完成安装,可能会出错,出错后重复运行gem install rails
3.建立rails应用。
path/to/ruby/bin> rails path/to/web
4.配置数据库连接
修改path/to/web/config/database.yml
development:
adapter: mysql
database: your_database_name
username: root
password: XXXXXX
host: localhost
5.配置支持中文
修改path/to/web/app/controllers/application.rb
# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
before_filter :configure_charsets
def configure_charsets
@response.headers["Content-Type"] = "text/html; charset=utf-8"
suppress(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
end
end
end
6.产生model/view/controller
path/to/web> ruby script/generate model table_Name
path/to/web> ruby script/generate view table_Name
path/to/web> ruby script/generate controller table_Name

数据真实table_Name+s.既如果table_name为:T_1,则数据库真实表名称为:T_1s
7.启动WEBrick
path/to/web> ruby script/server
启动WEBrick.

你可能感兴趣的:(ror)