0

I'm using kaminari for pagination in rails.

if I set default_scope order("created_at DESC") in model, it works as expected.

But when I write in controller like this, the DESC is ignored and pages are ordered by ascendent. (In this case I don't write default_scope in model.)

  def index
    @words = Word.order("created_at DESC").page params[:page]
  end

What am I doing wrong?

ironsand
  • 14,329
  • 17
  • 83
  • 176
  • doesn't look like there's anything wrong. Might be something in your view? – Sherwyn Goh Jan 23 '14 at 04:10
  • I think, there is nothing special in view. Like `@words.each do |word|` and so on. – ironsand Jan 23 '14 at 07:42
  • so running Word.all gives you the proper default scope, but running what you typed does not? Anyway it should be okay to just do Word.page(params[:page]) since the default scope is implemented? if you really can't just perform a .reverse to get things working for now – Sherwyn Goh Jan 23 '14 at 08:27

1 Answers1

1

In this case it applies both orders if want to ignore previous scope then use this:

@words = Word.unscoped.order("created_at DESC").page params[:page]
Ahmad Hussain
  • 2,443
  • 20
  • 27