0

我正在尝试将站点部署到engineyard,但我不断收到一个似乎是数据格式错误的错误。这只发生在作为生产部署到服务器集群上时。在本地或 VPS 上使用相同的数据库和代码库,我们没有问题。在我看来,这些错误表明突然有一个数组/哈希类型与某些用户数据不匹配。它似乎总是可以追溯到负责获取“选项”的模型。这些错误是由调用用户属性检查访问的模板触发的。

production log: 
 Completed 500 Internal Server Error in 32ms
 ** [Airbrake] Failure: Net::HTTPClientError

 ActionView::Template::Error (can't convert Symbol into Integer):
    18:         = admin_user.username
    19:         = username_helper(admin_user)
    20:       %td= country_image admin_user
    21:       %td= admin_user.account_name
    22:       %td
    23:         - if admin_user.is_a?(Creative)
    24:           - if admin_user.is_juror?
  app/models/user.rb:79:in `[]'
  app/models/user.rb:79:in `has_option?'
  app/models/contest_holder.rb:77:in `is_client_type?'
  app/models/contest_holder.rb:81:in `is_agent?'
  app/models/contest_holder.rb:70:in `ao_client_name'
  app/models/contest_holder.rb:115:in `account_name'
  app/views/admin/users/_users.html.haml:21:in `block in _app_views_admin_users__users_html_haml__845309245401675393_70184787547360'

trace:
ActionView::Template::Error: can't convert Symbol into Integer
Sample stack trace (show Rails)
 /app/models/user.rb:  79:in `[]'
 /app/models/user.rb:  79:in `has_option?'
…P/releases/20130814153250/app/models/contest_holder.rb:  77:in `is_client_type?'
…P/releases/20130814153250/app/models/contest_holder.rb:  81:in `is_agent?'
…P/releases/20130814153250/app/models/contest_holder.rb:  70:in `ao_client_name'
…P/releases/20130814153250/app/models/contest_holder.rb: 115:in `account_name'
…1/gems/haml-4.0.3/lib/haml/helpers/action_view_mods.rb:  10:in `block in render_with_haml'
…ed_gems/ruby/1.9.1/gems/haml-4.0.3/lib/haml/helpers.rb:  89:in `non_haml'
…1/gems/haml-4.0.3/lib/haml/helpers/action_view_mods.rb:  10:in `render_with_haml'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:  68:in `block in call'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:  56:in `each'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:  56:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…ruby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/builder.rb:  49:in `call'
…VP/releases/20130814153250/lib/middleware/force_ssl.rb:   8:in `call'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:  35:in `block in call'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:  34:in `catch'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:  34:in `call'
…ndled_gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/etag.rb:  23:in `call'
…/ruby/1.9.1/gems/rack-1.4.5/lib/rack/conditionalget.rb:  25:in `call'
…/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 210:in `context'
…/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 205:in `call'
…es/20130814153250/config/initializers/session_store.rb:  10:in `call'

来自 user.rb 的代码似乎是错误的联系点:

def has_option?(option)
 self.options[option] && self.options[option].to_s == "1"
end

一个选项值的例子: --- !map:ActiveSupport::HashWithIndifferentAccess is_agent: "1"

4

2 回答 2

1

来发现问题是数据库文件中的一个额外的换行符。具体来说,应用程序大量使用序列化的 yaml 数据。在 yaml 哈希键和值之间添加了一个额外的换行符,导致对象内出现错误。我们最初尝试创建一个脚本来清理数据库,然后发现它似乎只是从原始数据库文件中损坏了。

于 2013-08-21T02:22:50.230 回答
0

这是我的案子出了什么问题

Error : ActionView::Template::Error (can't convert Symbol into Integer)

原因:

在我的哈姆尔。

我试图从 json 对象访问属性。

object[:key]

但实际上它是一个 json 数组(来自活动记录 where 子句的实体数组)。我刚刚过滤了第一个元素。

希望有人会发现有用。

于 2014-11-18T11:09:56.133 回答