Skip to content

Instantly share code, notes, and snippets.

@tpendragon
Forked from anonymous/application.html.erb
Last active December 14, 2015 15:39
Show Gist options
  • Save tpendragon/5109691 to your computer and use it in GitHub Desktop.
Save tpendragon/5109691 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])
return redirect_to product_path(@products[0].id) if @products.length == 1
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