Will_Paginate and order clause do not work

I call a fairly simple function and cannot understand what is going on. (I am using rails 3.0.3 and the leading branch "will_paginate" gem). I have the following code:

  results = Article.search(params) # returns an array of articles
  @search_results = results.paginate :page => params[:page],  :per_page=>8, :order => order_clause

No matter what I do order_clause (for example, "article_title desc" and "article_title asc"), the results are always the same in the same order. Therefore, when I check the use of something of a type @search_results[0], the element is always the same. In my opinion, they are obviously always the same. Am I missing something?

I'm sure this is something stupid, but I hit my head against the wall all night. Any help would be greatly appreciated!

Edited to add: a search clause performs the following actions:

def self.search(params)
    full_text_search(params[:query].to_s).
    category_search(params[:article_category].blank? ? '' : params[:article_category][:name]).
    payout_search(params[:payout_direction], params[:payout_value]).
    length_search(params[:length_direction], params[:length_value]).
    pending.
    distinct.
    all
  end

where each of these guys is a search function like this:

#scopes
scope :text_search, lambda {|query|
    {
      :joins => "INNER JOIN users ON users.id IN (articles.writer_id, articles.buyer_id)",
      :conditions => ["(articles.article_title LIKE :query) OR
                       (articles.description LIKE :query) OR
                       (users.first_name LIKE :query) OR
                       (users.last_name LIKE :query)", { :query => "%#{query}%" }]
    }
  }
  scope :distinct, :select => "distinct articles.*"
#methods

    def self.payout_search(dir, val)
        return no_op if val.blank?
        send("payment_amount_#{dir.gsub(/\s+/,'').underscore}", val)
      end

      def self.length_search(dir, val)
        return no_op if val.blank?
        send("min_words_#{dir.gsub(/\s+/,'').underscore}", val)
      end

.

+3
1

github will_paginate, order :

@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'

paginate Post ( , - SQL , paginate). : " ". , :

  results = Model.limit(5).all
  @results = results.paginate :order => :doesnt_matter_anymore

, :

  results = Model.limit(5)
  @results = results.paginate :order => :matters

all . ActiveRecord SQL- . Will_paginate , paginate ( ...). Lazy Active Record Query Interface 3.0

+7

Source: https://habr.com/ru/post/1786059/


All Articles