2

一切正常,直到我推送到heroku,我认为这与mysql和postgres显示布尔值的不同方式有关?

我在Max OSX上使用Ruby 1.9.2p318Rails 3.2.2Mysql 5.2.35

这是我要运行的查询

@special_offers = Wine.find(:all, :include => [:inventories], :conditions => ["inventories.special = ? AND inventories.warehouse_id IN (?)", "true", @wharehouses_array], :order => "inventories.updated_at DESC", :limit => 3)

似乎问题出在inventories.special = ?, "true" 这在 mysql 上可以正常工作,但当我推送到 heroku 时却不行,这是使用 postgres

我尝试用 1 和“1”和“t”和 t 和 true 替换“true”,但似乎没有任何效果?


更新:
Heroku 日志文件

2012-04-04T14:06:58+00:00 app[web.1]: [2012-04-04 14:06:58] INFO  WEBrick 1.3.1
2012-04-04T14:06:58+00:00 app[web.1]: [2012-04-04 14:06:58] INFO  WEBrick::HTTPServer#start: pid=1 port=54181
2012-04-04T14:06:58+00:00 app[web.1]: [2012-04-04 14:06:58] INFO  ruby 1.9.2 (2011-07-09) [x86_64-linux]
2012-04-04T14:06:59+00:00 heroku[web.1]: State changed from starting to up
2012-04-04T14:07:01+00:00 app[web.1]: => Booting WEBrick
2012-04-04T14:07:01+00:00 app[web.1]: => Call with -d to detach
2012-04-04T14:07:01+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-04-04T14:07:01+00:00 app[web.1]: 
2012-04-04T14:07:01+00:00 app[web.1]: => Rails 3.2.2 application starting in production on http://0.0.0.0:54181
2012-04-04T14:07:01+00:00 app[web.1]: 
2012-04-04T14:07:01+00:00 app[web.1]: Started GET "/" for 41.119.121.138 at 2012-04-04 14:07:01 +0000
2012-04-04T14:07:02+00:00 app[web.1]: Processing by HomeController#index as HTML
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered partials/_display_wines.html.erb (169.1ms)
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered partials/_display_wines.html.erb (0.0ms)
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered partials/_display_wines.html.erb (8.1ms)
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered home/index.html.erb within layouts/application (259.9ms)
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered partials/_header_bar.html.erb (6.5ms)
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered partials/_main_links.html.erb (0.3ms)
2012-04-04T14:07:03+00:00 app[web.1]:   Rendered partials/_footer.html.erb (4.9ms)
2012-04-04T14:07:03+00:00 app[web.1]: Completed 200 OK in 1081ms (Views: 345.8ms | ActiveRecord: 175.7ms | Solr: 0.0ms)
2012-04-04T14:07:03+00:00 app[web.1]: cache: [GET /] miss
2012-04-04T14:07:03+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=1350ms status=200 bytes=36808
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/jquery.js dyno=web.1 queue=0 wait=0ms service=137ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/stylesheets/style1.css dyno=web.1 queue=0 wait=0ms service=179ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /stylesheets/style1.css] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /javascripts/jquery.js] miss

+00:00 app[web.1]: cache: [GET /javascripts/script1.js] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/script1.js dyno=web.1 queue=0 wait=0ms service=187ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/PIE.js dyno=web.1 queue=0 wait=0ms service=185ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/rails.js dyno=web.1 queue=0 wait=0ms service=189ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /javascripts/PIE.js] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /javascripts/rails.js] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/header_tile.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/header_tile.png dyno=web.1 queue=0 wait=0ms service=16ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/none.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/none.png dyno=web.1 queue=0 wait=0ms service=35ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/cybercellar_logo.jpg] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/flags.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/flags.png dyno=web.1 queue=0 wait=0ms service=96ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/cybercellar_logo.jpg dyno=web.1 queue=0 wait=0ms service=84ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/header_login.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/header_login.png dyno=web.1 queue=0 wait=0ms service=44ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/no_wine.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/no_wine.png dyno=web.1 queue=0 wait=0ms service=22ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/buttons2.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/buttons2.png dyno=web.1 queue=0 wait=0ms service=19ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/find_wine_wrap.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/find_wine_wrap.png dyno=web.1 queue=0 wait=0ms service=22ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/comment.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/comment.png dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/bullet.png] miss

4:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/bullet.png dyno=web.1 queue=0 wait=0ms service=13ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/buttons.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/buttons.png dyno=web.1 queue=0 wait=0ms service=12ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/links_bar.png] miss
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/hr_light.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/hr_light.png dyno=web.1 queue=0 wait=0ms service=12ms status=304 bytes=0
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/links_bar.png dyno=web.1 queue=0 wait=0ms service=17ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/cart_background.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/cart_background.png dyno=web.1 queue=0 wait=0ms service=4ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/home_page_image.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/home_page_image.png dyno=web.1 queue=0 wait=0ms service=6ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/find_wine.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/find_wine.png dyno=web.1 queue=0 wait=0ms service=10ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/footer_tile.jpg] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/footer_tile.jpg dyno=web.1 queue=0 wait=0ms service=7ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/social.png] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/hr_dark.jpg dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/hr_dark.jpg] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/social.png dyno=web.1 queue=0 wait=0ms service=6ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/credit_cards.png] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/credit_cards.png dyno=web.1 queue=0 wait=0ms service=14ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/money_back.png] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/money_back.png dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0



架构文件:用于库存表

create_table "inventories", :force => true do |t|
    t.integer   "wine_id"
    t.integer   "warehouse_id"
    t.integer   "stock"
    t.float     "price"
    t.integer   "quantity_id"
    t.timestamp "created_at"
    t.timestamp "updated_at"
    t.boolean   "available",                        :default => false
    t.boolean   "discount",                         :default => false
    t.string    "markupprofile_id",   :limit => 45
    t.string    "discountprofile_id", :limit => 45
    t.float     "discount_price"
    t.boolean   "special",                          :default => false
  end
4

1 回答 1

2

使用实际的 TrueClass,而不是字符串,Rails 会为您将其转换为正确的查询。

正确的:

"inventories.special = ?", true

不正确:

"inventories.special = ?", "true"

它不会引发错误,因为第二个仍然会产生有效的查询,它只是在寻找其中 special 是包含实际真实字符的字符串的记录。

于 2012-04-04T14:23:03.037 回答