All threads / How do I implement a default_scope order when I'm using searchkick?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I implement a default_scope order when I'm using searchkick?

Jeramae Bohol asked in General

Before I implemented searchkick/elasticsearch on my rails app, the default_scope -> { order(created_at: :desc) } works. But after implementing searchkick/elasticsearch, it doesn't work anymore.

Since Searchkick is a whole separate process, it won't know about your Rails stuff. What I would say is if you write a helper method or class you can have it apply that scope to the options you pass in so that it always searches the same default scope.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 35,699+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.