Groups
Groups
Sign in
Groups
Groups
rails4scm
Conversations
About
Send feedback
Help
RAILS 连接ORACLE库并不复杂
2 views
Skip to first unread message
大师傅
unread,
Sep 4, 2007, 4:19:31 AM
9/4/07
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rails4scm
RAILS连接ORACLE数据库成功。中间的日志如下,供大家参考:
1)下载 ruby-oci8-1.0.0-rc1-mswin32.rb 并在CMD下执行之, 提示成功。
2)修改database.yml 如下(注意每个冒号后都要有空格, #后东西就别抄了,中文有干扰):
development:
adapter: oci
database: # 不用填,填了也无用,ORACLE用的式模式
username: SC # 模式/用户
password: oracle
host: ORCL # TNS名, 用TNSPING先看看是否OK
3)建立了一个简单的ITEMS表, 最好用复数, 而且主键式NUMBER型的ID字段
4)在CMD下执行 ruby script/generate scaffold Item Manage 建立C、R、U、D的程序
5)启动服务,没报错。但由于是第一次改了database.yml没有重新启动,所以在IE中执行
//localhost:3000/Manage时, ORACLE报错,找不到TNS, 重启就OK了
6)新增一个ITEM对象,报告ORA-02289错误,说序列不存在。查网站,才知道要建立一个对应序列
所以在pl-sql下建立一个新的ITEMS_SEQ序列,就一切正常了
7)数据库中的中文显示???, 把页面改为GBK编码显示正常,为此修改application.rb如下:
before_filter :configure_charsets
def configure_charsets
@response.headers["Content-Type"] = "text/html; charset=GBK"
suppress(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
end
end
8)改后,数据库取存、显示都正常。 看来ORACLE对多国语言的处理比MYSQL要强,所以只控制RAILS的输出页面的"Content-
Type"就OK了。
Reply all
Reply to author
Forward
0 new messages