无法将 Fixnum 转换为字符串 - Devise/sessions 控制器问题

发布于 2024-10-13 01:15:33 字数 3092 浏览 2 评论 0原文

所以这是我看到的错误:

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)

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

So this is the error I see:

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'

This is how application_controller.rb looks:

    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

Help!

Edit1: Per the request, here is the output of the log file.

    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)

Anyone come up with any solutions for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

香橙ぽ 2024-10-20 01:15:33

好吧,我终于找到了答案。数据库已损坏。一旦我转储了整个数据库,删除了数据库文件并重新创建了所有内容 - 我就可以开始了。

叹气

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

Ok so I finally found the answer. The db got corrupt. Once I dumped the entire db, deleted the db file and re-created everything - I was good to go.

sigh

I just hope I can figure out a way to prevent that from happening in production.

雄赳赳气昂昂 2024-10-20 01:15:33

您确定以下内容位于正确的whatever_controller.rb中吗?

  before_filter :authenticate_user!

Are you sure that the following is in your correct whatever_controller.rb?

  before_filter :authenticate_user!
隱形的亼 2024-10-20 01:15:33

你把数据库密码设置为纯数字了吗?我的数据库密码在开发机上是111111,根据错误信息“can't conversion Fixnum into String”,我想我应该将数据库密码更改为非-数字“abcdef”并且成功了!

did you set the database password to be a pure number? My database password was 111111 in the devlopment machine, according to the error info "can't convert Fixnum into String", I guess i should change database password to be non-numeric "abcdef" and it worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文