rails2.3.5中,

调用方法:
=begin
方法名:user_login
如果用户名密码相同,登录成功 将 session[:user_id] = @user.id将用户id存到session user_id中
否则登录失败
=end

def user_login
is_not_null
@user_name=params[:qa_user_name]
@pass_word=params[:qa_pass_word]
@pwdsalt= QaUser.get_pwdsalt(@user_name)
@qa_auto=params[:qa_auto]
@userck=QaCookie.check_cookie(@pwdsalt)
#if check_code ==1 && validate_password == 1
begin
#判断是否登录成功
if check_code ==1 && validate_password == 1
@qa_user_pass=QaUser.check_qa_user_login(@user_name,@pass_word)
if @qa_user_pass.to_i == 1
session[:user_id] = @qa_user_pass.id
puts 'login_ok'
puts session[:user_id]
render :json=>{:lg=>{:msg =>"login_ok"}}.to_json

#是否自动登录系统
if @qa_auto.to_i==1 and @userck==1

cookies[:smn_token]={:value=>@pwdsalt,:expires => Time.now + 7.days}
else
QaCookie.create(:qa_cookie_name=>@user_name,:qa_cookie_pwdsalt=>@pwdsalt)
cookies[:smn_token]={:value=>@pwdsalt,:expires => Time.now + 7.days}
end
else
session[:qa_user_id] = nil
puts 'login_fail'
render :json=>{:lg=>{:msg =>"login_fail"}}.to_json
end
end
rescue Exception=>e
puts e.message
end
end

调用该方法,出错如下:
错误信息:
Processing QaUserController#user_login (for 127.0.0.1 at 2010-06-18 16:19:56) [POST]
Parameters: {"qa_auto"=>"0", "qa_pass_word"=>"fy123", "qa_cpass_word"=>"fy123", "authenticity_token"=>"ECNnc7Bv2JKUArGUzJ8VIuOhX1ynN7C2zYuW+PeWxf8=", "qa_check"=>"qjnf", "qa_user_name"=>"fyname"}
[4;36;1mSQL (0.0ms)[0m [0;1mBEGIN[0m
[4;35;1mQaUser Load (0.0ms)[0m [0mSELECT * FROM `qa_users` WHERE (qa_users_name='fyname') LIMIT 1[0m
[4;36;1mQaUser Columns (15.0ms)[0m [0;1mSHOW FIELDS FROM `qa_users`[0m
[4;35;1mSQL (0.0ms)[0m [0mCOMMIT[0m
[4;36;1mQaCookie Load (0.0ms)[0m [0;1mSELECT * FROM `qa_cookies` WHERE (qa_cookie_pwdsalt='ed4dc7aa7a4f85aeaf776ab471e779568217f97f4426358633b01c3111556103') LIMIT 1[0m
[4;35;1mQaUser Load (0.0ms)[0m [0mSELECT * FROM `qa_users` WHERE (qa_users_name = 'fyname') LIMIT 1[0m
[4;36;1mQaCookie Columns (16.0ms)[0m [0;1mSHOW FIELDS FROM `qa_cookies`[0m
[4;35;1mSQL (0.0ms)[0m [0mBEGIN[0m
[4;36;1mQaCookie Create (0.0ms)[0m [0;1mINSERT INTO `qa_cookies` (`qa_cookie_name`, `updated_at`, `qa_cookie_pwdsalt`, `created_at`) VALUES('fyname', '2010-06-18 08:19:57', 'ed4dc7aa7a4f85aeaf776ab471e779568217f97f4426358633b01c3111556103', '2010-06-18 08:19:57')[0m
[4;35;1mSQL (32.0ms)[0m [0mCOMMIT[0m
Completed in 1032ms (View: 16, DB: 63) | 200 OK [http://localhost/qa_user/user_login]
Fri Jun 18 16:19:57 +0800 2010: Read error: #<ArgumentError: wrong number of arguments (0 for 1)>
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2155:in `hash'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2155:in `[]'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2155:in `subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2036:in `inject'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `each'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `inject'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:406:in `reset_subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:63:in `cleanup_application'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:17:in `close'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:82:in `process'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in `process_client'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `each'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `process_client'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `initialize'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `new'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `initialize'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `new'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
D:/Ruby/ruby-1.8.6-p111/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3错误信息:
Processing QaUserController#user_login (for 127.0.0.1 at 2010-06-18 16:19:56) [POST]
Parameters: {"qa_auto"=>"0", "qa_pass_word"=>"fy123", "qa_cpass_word"=>"fy123", "authenticity_token"=>"ECNnc7Bv2JKUArGUzJ8VIuOhX1ynN7C2zYuW+PeWxf8=", "qa_check"=>"qjnf", "qa_user_name"=>"fyname"}
[4;36;1mSQL (0.0ms)[0m [0;1mBEGIN[0m
[4;35;1mQaUser Load (0.0ms)[0m [0mSELECT * FROM `qa_users` WHERE (qa_users_name='fyname') LIMIT 1[0m
[4;36;1mQaUser Columns (15.0ms)[0m [0;1mSHOW FIELDS FROM `qa_users`[0m
[4;35;1mSQL (0.0ms)[0m [0mCOMMIT[0m
[4;36;1mQaCookie Load (0.0ms)[0m [0;1mSELECT * FROM `qa_cookies` WHERE (qa_cookie_pwdsalt='ed4dc7aa7a4f85aeaf776ab471e779568217f97f4426358633b01c3111556103') LIMIT 1[0m
[4;35;1mQaUser Load (0.0ms)[0m [0mSELECT * FROM `qa_users` WHERE (qa_users_name = 'fyname') LIMIT 1[0m
[4;36;1mQaCookie Columns (16.0ms)[0m [0;1mSHOW FIELDS FROM `qa_cookies`[0m
[4;35;1mSQL (0.0ms)[0m [0mBEGIN[0m
[4;36;1mQaCookie Create (0.0ms)[0m [0;1mINSERT INTO `qa_cookies` (`qa_cookie_name`, `updated_at`, `qa_cookie_pwdsalt`, `created_at`) VALUES('fyname', '2010-06-18 08:19:57', 'ed4dc7aa7a4f85aeaf776ab471e779568217f97f4426358633b01c3111556103', '2010-06-18 08:19:57')[0m
[4;35;1mSQL (32.0ms)[0m [0mCOMMIT[0m
Completed in 1032ms (View: 16, DB: 63) | 200 OK [http://localhost/qa_user/user_login]
Fri Jun 18 16:19:57 +0800 2010: Read error: #<ArgumentError: wrong number of arguments (0 for 1)>
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2155:in `hash'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2155:in `[]'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2155:in `subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2036:in `inject'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `each'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `inject'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2156:in `subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:406:in `reset_subclasses'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:63:in `cleanup_application'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:17:in `close'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:82:in `process'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in `process_client'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `each'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `process_client'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `initialize'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `new'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `initialize'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `new'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in `run'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
D:/Ruby/ruby-1.8.6-p111/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
D:/Ruby/ruby-1.8.6-p111/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3

调试发现 mongrel的 process_client(client)方法的
rescue Object => e
STDERR.puts "#{Time.now}: Read error: #{e.inspect}"
STDERR.puts e.backtrace.join("\n")
报错:
def process_client(client)
begin
parser = HttpParser.new
params = HttpParams.new
request = nil
data = client.readpartial(Const::CHUNK_SIZE)
nparsed = 0

# Assumption: nparsed will always be less since data will get filled with more
# after each parsing. If it doesn't get more then there was a problem
# with the read operation on the client socket. Effect is to stop processing when the
# socket can't fill the buffer for further parsing.
while nparsed < data.length
nparsed = parser.execute(params, data, nparsed)

if parser.finished?
if not params[Const::REQUEST_PATH]
# it might be a dumbass full host request header
uri = URI.parse(params[Const::REQUEST_URI])
params[Const::REQUEST_PATH] = uri.path
end

raise "No REQUEST PATH" if not params[Const::REQUEST_PATH]

script_name, path_info, handlers = @classifier.resolve(params[Const::REQUEST_PATH])

if handlers
params[Const::PATH_INFO] = path_info
params[Const::SCRIPT_NAME] = script_name

# From http://www.ietf.org/rfc/rfc3875 :
# "Script authors should be aware that the REMOTE_ADDR and REMOTE_HOST
# meta-variables (see sections 4.1.8 and 4.1.9) may not identify the
# ultimate source of the request. They identify the client for the
# immediate request to the server; that client may be a proxy, gateway,
# or other intermediary acting on behalf of the actual source client."
params[Const::REMOTE_ADDR] = client.peeraddr.last

# select handlers that want more detailed request notification
notifiers = handlers.select { |h| h.request_notify }
request = HttpRequest.new(params, client, notifiers)

# in the case of large file uploads the user could close the socket, so skip those requests
break if request.body == nil # nil signals from HttpRequest::initialize that the request was aborted

# request is good so far, continue processing the response
response = HttpResponse.new(client)

# Process each handler in registered order until we run out or one finalizes the response.
handlers.each do |handler|
handler.process(request, response)
break if response.done or client.closed?
end

# And finally, if nobody closed the response off, we finalize it.
unless response.done or client.closed?
response.finished
end
else
# Didn't find it, return a stock 404 response.
client.write(Const::ERROR_404_RESPONSE)
end

break #done
else
# Parser is not done, queue up more data to read and continue parsing
chunk = client.readpartial(Const::CHUNK_SIZE)
break if !chunk or chunk.length == 0 # read failed, stop processing

data << chunk
if data.length >= Const::MAX_HEADER
raise HttpParserError.new("HEADER is longer than allowed, aborting client early.")
end
end
end
rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
client.close rescue nil
rescue HttpParserError => e
STDERR.puts "#{Time.now}: HTTP parse error, malformed request (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #{e.inspect}"
STDERR.puts "#{Time.now}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n"
rescue Errno::EMFILE
reap_dead_workers('too many files')
rescue Object => e
STDERR.puts "#{Time.now}: Read error: #{e.inspect}"
STDERR.puts e.backtrace.join("\n")
ensure
begin
client.close
rescue IOError
# Already closed
rescue Object => e
STDERR.puts "#{Time.now}: Client error: #{e.inspect}"
STDERR.puts e.backtrace.join("\n")
end
request.body.delete if request and request.body.class == Tempfile
end

提示信息“ Read error: #<ArgumentError: wrong number of arguments (0 for 1)> 提示应该是少传入一个参数,但是代码那部分少传,user_login 正常的,未少传入参数,这是什么原因出错?如何解决该问题?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值