-
-
Save tpendragon/5109691 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
<%= form_tag products_path, method: :get do %> | |
<p> | |
<%= text_field_tag :search, params[:search] %> | |
<%= submit_tag "Search", title: nil %> | |
</p> | |
<% end %> |
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 self.search(search) | |
if search | |
find(:all, :conditions => ['title LIKE ?', "%#{search}%"]) | |
else | |
find(:all) | |
end | |
end |
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 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