代码很简单,Temp2 表中有一列 man_id 是空的,首页 index.erb 会选出一条然后人工用 select 选一个 bid 做对应 save 后又转到 index 去,但是经常用着用着就报下面错误。是不是要关闭连接?
ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5.000 seconds (waited 5.000 seconds):
大概代码如下
ActiveRecord::Base.establish_connection(
:adapter => 'mysql2',
:database => 'mandb', #oracle service name
:username => 'root',
:password => '')
get '/' do
@t_man = Temp2.where("man_id is NULL").first
if @t_man.nil?
erb :success
else
erb :index
end
end
post '/save' do
tid = params['tid']
bid = params['bid']
if bid==-1
redirect to('/')
end
t = Temp2.where("tid=#{tid}").first
if !t.nil?
t.man_id = bid
t.save
end
redirect to('/')
end