LoginSignup
6
6

More than 5 years have passed since last update.

mongodbを使用するとkaminariでorderが使えない

Last updated at Posted at 2014-04-19

問題

def index
  @tweets = Tweet.page(params[:page]).per(50).order("id desc")
end

みたいなことをやりたいが

undefined method `order' for #<Mongoid::Criteria:0x007fb98df18aa8>

と出力されてしまう.

解決法

def index
  @tweets = Tweet.page(params[:page]).per(50).desc(:id)
end

desc(:id)のように書く.

調査不足なので,mongodbを使った場合特有の現象なのかは調べきれていませんが,これでやりたいことができたので共有します!

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6