私のコントローラーでは、私の filter_with_params() メソッドが、その上に will_paginate をスタックしようとすると、postgres で構文エラーを引き起こしています。
私のコントローラーでは、次のように呼び出します。
@styles = Style.filter_with_params(params).paginate(:page => params[:page], :per_page => 6)
モデル方法:
class Style < ActiveRecord::Base
def self.filter_with_params(params)
    scoped = where("styles.item != ''")
    if params[:t]
      scoped = scoped.joins(:tags)
      scoped = scoped.select("distinct styles.*, count(*) AS count")
      scoped = scoped.where(tags: { name: params[:t] })
      scoped = scoped.group('styles.id')
      scoped = scoped.having("count(*) = #{params[:t].size}")
    end
    scoped
end
基本的に、私のフィルタ メソッドはタグを探しているので、それらの結果の上にページを追加する必要があります。似たような経験をした人はいますか?
このアプリではRails 3を使用しています
ここにpostgresエラーがあります
PG::Error: ERROR:  syntax error at or near "distinct" LINE 1: SELECT COUNT(*) AS count_all, distinct styles.*, count(*) AS...
                                  ^
: SELECT COUNT(*) AS count_all, distinct styles.*, count(*) AS count, styles.id AS styles_id FROM "styles" INNER JOIN "tagizations" ON "tagizations"."style_id" = "styles"."id" INNER JOIN "tags" ON "tags"."id" = "tagizations"."tag_id" WHERE "tags"."name" IN ('engagement') AND (styles.polenza_item != '') GROUP BY styles.id HAVING count(*) = 1