Skip to content

Instantly share code, notes, and snippets.

Created March 7, 2013 16:51
Show Gist options
  • Save anonymous/5109587 to your computer and use it in GitHub Desktop.
Save anonymous/5109587 to your computer and use it in GitHub Desktop.
<%= form_tag products_path, method: :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", title: nil %>
</p>
<% end %>
def self.search(search)
if search
find(:all, :conditions => ['title LIKE ?', "%#{search}%"])
else
find(:all)
end
end
def index
@products = Product.search(params[:search])
respond_to do |format|
format.html
format.json { render json: @products }
end
end
def show
@product = Product.find(params[:id])
@cart = current_cart #Get current cart
respond_to do |format|
format.html
format.json { render json: @product }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment