2012-05-01 3 views
1

기본적으로 두 가지 유형의 상태가 있습니다. status_id가 "2"이고 status_id가 "5"인 두 속성을 표시하고 싶습니다. 속성에는 두 가지 상태가 없습니다. 나는 여기에 &을 사용하고 싶지 않다는 것을 안다. 그리고 나는 성명을 발표 할 수 있기를 바란다. 그러나 어떻게 그렇게 할 것인지 잘 모르겠다. 이것은 내가 status_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'}) 

어떤 도움

주시면 감사하겠습니다 ... 다음, 확실하지 않은 모습 범위를 가지고있다.

답변

1

대신 paginate 호출 :conditions를 사용하여, IMO 같은 where를 사용하여 명확하고 쉬울 것 :이 또한 가능하다

@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] }) 
+0

'where' 문은 페이지에서 물건을 지키기 위해 가장 잘 작동했습니다 inate 전화. 무리 감사! – mediarts