Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created September 4, 2009 07:42
Show Gist options
  • Save sprite2005/180788 to your computer and use it in GitHub Desktop.
Save sprite2005/180788 to your computer and use it in GitHub Desktop.
def search
@products = Products.search params[:q]
asins = @products.collect{ |e| e.asin }.to_a
existing_products = Products.find(:all, :conditions => {:asin => asins})
existing_asins = existing_products.collect{|e| e.asin}
@products.delete_if { |e| existing_asins.include?(e.asin)}
@products.insert(0, existing_products).flatten!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment