I am using the gem metasearch to provide some sorting features. The page is defaulting to a sort of created_at ASC
, but I want it to be created_at DESC
, but I can't explicitly state that because it will override MetaSearch's sort features.
def index
@search = Photo.search(params[:search])
end
Any thoughts on how to achieve this?
I had the same problem and ended up doing like this in the controller
search = {"meta_sort" => "created_at.desc"}.merge(params[:search] || {})
@search = Photo.search(search)
Default sort order is created_at DESC, but it will be overwritten if a new sort order is received in the params. Seems to work for me.
Try this approach. It works for me:
def index
@search = Photo.search(params[:search])
@photos = @search.order("created_at desc")
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With