Rails:我的ruby代码打破了heroku

Ala*_*man 0 ruby ruby-on-rails heroku

我视图中的Ruby代码在heroku上崩溃了我的rails应用程序.同时它也在开发中.我正在使用HAML.

    = @sold
    - @sold.each do |x|
      %p lorem
Run Code Online (Sandbox Code Playgroud)

无论@sold是否等于nil还是有值,它都会在第二行 中断- @sold.each do |x|.你们有什么线索的原因吗?

控制器:

  def activity
    @user = current_user 
    @selling = @user.products.where( "quantity != ?", 0 )
    @sold = @user.products.where( "quantity == ?", 0 )
  end
Run Code Online (Sandbox Code Playgroud)

编辑: Heroku日志说

"HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

2013-10-21T03:21:40.646768+00:00 app[web.1]:     21:           %p one
2013-10-21T03:21:40.646570+00:00 app[web.1]:     20:         - @sold.each do |x|
2013-10-21T03:21:40.646570+00:00 app[web.1]:     17:             %button Status
2013-10-21T03:21:40.646570+00:00 app[web.1]:     18:       %tbody
2013-10-21T03:21:40.646570+00:00 app[web.1]:     19:         = @sold
2013-10-21T03:21:40.646768+00:00 app[web.1]:   app/views/users/activity.html.haml:20:in `_app_views_users_activity_html_haml___1193554036748909609_69954007105480
Run Code Online (Sandbox Code Playgroud)

Rya*_*igg 6

尝试更改此行:

@sold = @user.products.where("quantity == ?", 0)
Run Code Online (Sandbox Code Playgroud)

对此:

@sold = @user.products.where(quantity: 0)
Run Code Online (Sandbox Code Playgroud)

我认为问题是因为你试图在PostgreSQL中使用double equals作为匹配器,但它并不支持它.=如果你想在那里检查相等性,你应该使用.

  • 或使用好的AR哈希语法,例如.`where(数量:0)` (3认同)
  • @AlainGoldman:是的,PostgreSQL理解`!=`.您可能希望花一些时间来查看[文档](http://www.postgresql.org/docs/current/interactive/index.html),如果您打算在PostgreSQL上真的应该开发在PostgreSQL上部署(不,AR不会让你与数据库之间的差异隔离,甚至不会关闭). (2认同)