ruby-on-railsruby-on-rails-3meta-search

MetaSearch sort ordered column


I have a model:

class Event < ActiveRecord::Base
  default_scope :order => 'date_begin'
end

There is a sort link in a view file:

= sort_link @search, :date_begin

When I'm trying to order date_begin as DESC nothing happens because the SQL query is:

SELECT * FROM events ORDER BY date_begin, date_begin DESC

How to make MetaSearch reorder this column? (I know that there is a "reorder" method in ActiveRecord but I don't know how to apply it to MetaSearch)


Solution

  • You can use unscoped method when you decided to use meta_search:

    @search = Event.unscoped.search(params[:search])