Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Created June 4, 2012 18:43
Show Gist options
  • Save ornerymoose/2870125 to your computer and use it in GitHub Desktop.
Save ornerymoose/2870125 to your computer and use it in GitHub Desktop.
- content_for :javascripts do
- cache('search_autocomplete') do
:javascript
$(function(){
var products = #{auto_complete_products.to_json};
$("#keywords").autocomplete(products,{
appendToElement: ".autocomplete"
});
});
.search.autocomplete
= form_tag product_search_path, :method => :get do
= text_field_tag :keywords, params[:keywords], :placeholder => 'Search for: Gift Cards, Online Coupon Codes, Promos and More...', :class => "small"
%button{:type => 'submit', :class => 'button secondary search'}
%span#top_search Search
def auto_complete_products
product_names = Product.select('distinct products.name').active.on_hand.map(&:name)
merchant_names = Couponcodes::Merchant.select("distinct store_name").active.by_store_name.map(&:store_name)
product_source_image = ProductSource.find_by_name("").image(:thumb) #how do i tap into all ProductSource names?
(product_names + merchant_names + product_source_image).uniq.sort
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment