2012-09-20 29 views
1

我想在我的軌道項目上添加Kaminari分頁的條件,我發現它幾乎是不可能的。這裏是我的代碼Kaminari分欄與軌道上的條件

UserController 
#feed=Feed.order('created_at desc').page(params[:page], :conditions=>["source=? or  source=?","beep","sub_beep"]) 

上面沒有洙工作,我嘗試以下

@feed1 = Feed.find(:all,:conditions=>["source=? or source=?","beep","sub_beep"]) 
    @feed= Kaminari.paginate_array(@feed1).page(params[:page]).per(2) 

上面顯示的內容,但它不顯示每頁2項內容和顯示的元素的arent訂購。

我需要一種方法來添加分頁雷條件,責令結果

請我需要幫助! :(

回答

1

雷設計與ActiveRecord的3+風格查詢唯一接口的工作。

請避免使用:conditions「Hasheritis」語法將在早晚過時,但鏈where方法來代替。

where方法

使用是很好這裏記錄軌道上的指南:http://guides.rubyonrails.org/active_record_querying.html#conditions

控制器代碼應該是這樣的:

feeds = Feed.where(:source => ['beep', 'sub_beep']).order('created_at desc').page(params[:page])