2016-08-04 62 views
0

我想做一个包含这两个参数的语句,但我总是收到“错误的绑定变量数”错误。我已经发布了下面的代码。任何帮助表示赞赏。Rails控制器中绑定变量错误的数量错误

控制器:

@open_houses = OpenHouse.upcoming.where('open_houses.start_date >= ?', Date.current, listing_id: @listing.id).order(start_date: :asc) 

错误:

enter image description here

+0

是的,你将2个参数传递给'.where()'.. - >'Date.current,listing_id:@ listing.id'。它应该是1. –

+0

你可以这样写:'where('open_houses.start_date> =?AND listing_id =?',Date.current,@ listing.id)'.. –

回答

2

你必须写是这样的:因为当轨道看where('open_houses.start_date >= ?', Date.current, listing_id: @listing.id),预计where('open_houses.start_date >= ? AND listing_id = :listing_id', Date.current, listing_id: @listing.id),但我认为

OpenHouse. 
    upcoming. 
    where(listing_id: @listing.id). 
    where('open_houses.start_date >= ?', Date.current). 
    order(start_date: :asm) 

你没有期待。