无法将Fixnum转换为String - 设计/会话控制器问题

时间:2011-01-19 21:05:15

标签: ruby-on-rails ruby-on-rails-3 devise declarative-authorization

所以这是我看到的错误:

TypeError in Devise/sessionsController#create

can't convert Fixnum into String

Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:21:in `set_current_user'

这就是application_controller.rb的外观:

    class ApplicationController < ActionController::Base
  helper :all
   helper_method :current_user, :logged_in?

  protect_from_forgery
  before_filter :set_current_user

  def set_xhr_flash
    flash.discard if request.xhr?
  end

  def correct_safari_and_ie_accept_headers
    ajax_request_types = ['text/javascript', 'application/json', 'text/xml']
    request.accepts.sort! { |x, y| ajax_request_types.include?(y.to_s) ? 1 : -1 } if request.xhr?
  end


  protected 

  def set_current_user
    Authorization.current_user = current_user
  end

end

帮助!

Edit1:根据请求,这是日志文件的输出。

    User Load (0.3ms)  SELECT "users".* FROM "users" WHERE ("users"."username" = 'test') LIMIT 1
Completed   in 289ms

TypeError (can't convert Fixnum into String):
  app/controllers/application_controller.rb:21:in `set_current_user'

Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (340.7ms)
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (350.6ms)


Started GET "/users/login" for 127.0.0.1 at 2011-01-19 17:16:18 -0500
  Processing by Devise::SessionsController#new as HTML
nil
Rendered devise/sessions/new.html.erb within layouts/application (5.9ms)
Completed 200 OK in 65ms (Views: 15.6ms | ActiveRecord: 0.0ms)


Started POST "/users/login" for 127.0.0.1 at 2011-01-19 17:16:31 -0500
  Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"+SYzwvqO1Kp8GhYwSA9u3plM5A/RNNRFT3wzJICXP6s=", "user"=>{"f_name"=>"First Name", "l_name"=>"Last Name", "username"=>"test", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"Email Address"}, "commit"=>"Submit"}
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE ("users"."username" = 'test') LIMIT 1
Completed   in 199ms

TypeError (can't convert Fixnum into String):
  app/controllers/application_controller.rb:21:in `set_current_user'

Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (348.3ms)
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (355.7ms)

有人为此提出任何解决方案吗?

3 个答案:

答案 0 :(得分:2)

好的,我终于找到了答案。数据库损坏了。一旦我转储了整个数据库,删除了db文件并重新创建了所有内容 - 我很高兴。

叹息

我希望我能找到一种方法来防止这种情况在生产中发生。

答案 1 :(得分:0)

你确定以下是正确的whatever_controller.rb吗?

  before_filter :authenticate_user!

答案 2 :(得分:0)

您是否将数据库密码设置为纯数字?我的数据库密码在开发机器中是111111,根据错误信息"can't convert Fixnum into String",我想我应该将数据库密码更改为非数字“abcdef”并且它有效!