Order in building up the SQL query fixed

This commit is contained in:
Christoph Haas 2013-08-08 21:49:46 +02:00
parent 47b3253de3
commit fca503df55

View file

@ -2,17 +2,19 @@ class PackagesController < ApplicationController
def index def index
@packages = Package @packages = Package
if params[:search]
#@packages = @packages.where("packages.name @@ :q or packages.description @@ :q", q: params[:search])
@packages = @packages.text_search(params[:search])
end
if params[:with_screenshots]=='yes' if params[:with_screenshots]=='yes'
# Limit the packages to those that have approved screenshots. # Limit the packages to those that have approved screenshots.
# Also eager-load the screenshots. # Also eager-load the screenshots.
@packages = @packages.includes(:screenshots).where("screenshots.approved"=>true) @packages = @packages.includes(:screenshots).where("screenshots.approved"=>true)
end end
if params[:search] #@packages = @packages.order('name').limit(20)
@packages = @packages.where("packages.name @@ :q or packages.description @@ :q", q: params[:search]) @packages = @packages.limit(20)
end
@packages = @packages.order('name').limit(20)
end end
def with_screenshots def with_screenshots