Created
June 4, 2012 18:43
-
-
Save ornerymoose/2870125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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