Ruby on rails 3.1 Rails,在条件中用or语句分页

Ruby on rails 3.1 Rails,在条件中用or语句分页,ruby-on-rails-3.1,will-paginate,Ruby On Rails 3.1,Will Paginate,所以基本上我有两种状态,我想显示状态为2和状态为5的属性,属性从来没有两种状态,所以我知道我不想使用&在这里,我希望能够使用and或语句,但我不确定如何去做。这就是我必须显示的状态,id为“2”,它工作得很好 @properties = Property.order("updated_at DESC").paginate(:per_page => 20, :page => params[:page], :conditions => { :status_id => '2'

所以基本上我有两种状态,我想显示状态为2和状态为5的属性,属性从来没有两种状态,所以我知道我不想使用&在这里,我希望能够使用and或语句,但我不确定如何去做。这就是我必须显示的状态,id为“2”,它工作得很好

@properties = Property.order("updated_at DESC").paginate(:per_page => 20, :page => params[:page], :conditions => { :status_id => '2' })
在我的模型中,我也有如下的作用域,不确定我是否可以这样做

scope :for_sale, joins(:status).where(:statuses => { :current => 'For Sale'})
scope :market_listings, joins(:status).where(:statuses => { :current => 'Market Listing'})

任何帮助都将不胜感激。

paginate
调用中使用
:conditions
,而不是使用
:conditions
,这样使用
会更清晰、更容易:

@properties = Property.where('status_id = 2 or status_id = 5').order("updated_at DESC").paginate(:per_page => 20, :page => params[:page])
这也是可能的:

@properties = Property.order("updated_at DESC").paginate(:per_page => 20, :page => params[:page], :conditions => 'status_id = 2 or status_id = 5')
或者更简单:

@properties = Property.order("updated_at DESC").paginate(:per_page => 20, :page => params[:page], :conditions => { :status_id => [2,5] })

与其在
paginate
调用中使用
:conditions
,不如在
中这样使用

@properties = Property.where('status_id = 2 or status_id = 5').order("updated_at DESC").paginate(:per_page => 20, :page => params[:page])
这也是可能的:

@properties = Property.order("updated_at DESC").paginate(:per_page => 20, :page => params[:page], :conditions => 'status_id = 2 or status_id = 5')
或者更简单:

@properties = Property.order("updated_at DESC").paginate(:per_page => 20, :page => params[:page], :conditions => { :status_id => [2,5] })

where
语句最有效地阻止了paginate调用。非常感谢!
where
语句最有效地阻止了paginate调用。非常感谢!