我正在尝试将一个站点部署到engineyard上,并且我一直收到一个似乎是数据格式错误的错误。这仅在作为生产部署到服务器群集时发生。在本地或在VPS上使用相同的DB和代码库我们没有问题。 在我看来,错误表明突然存在一些数据/散列类型与某些用户数据不匹配。它似乎总是追溯到模型,它的任务是获得“选项”。这些错误由要求访问用户属性检查的模板触发。
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"
答案 0 :(得分:1)
发现该问题是数据库文件中的额外换行符。具体而言,该应用程序使用相当数量的序列化yaml数据。在yaml散列键和值之间添加了一个额外的换行符,导致对象内部出现错误。我们最初尝试创建一个脚本来清理数据库,然后发现它似乎只是从原始数据库文件中损坏了。
答案 1 :(得分:0)
这是我的案例错误
Error : ActionView::Template::Error (can't convert Symbol into Integer)
原因:
在我的haml中。
我试图从json对象访问属性。
object[:key]
但实际上它是一个json数组(来自active record where子句的实体数组)。我刚刚过滤了第一个元素。
希望有人会觉得有用。