Created
November 20, 2011 22:39
-
-
Save sapient/1381078 to your computer and use it in GitHub Desktop.
NEVER DO THIS
This file contains hidden or 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 show | |
if params["product_search"].present? | |
@product = Product.find_by_name(params["product_search"][:name]) | |
if @product.blank? | |
redirect_to(products_path, :notice => "Not Found") | |
return | |
end | |
else | |
@product = Product.find(params[:id]) | |
end | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @product } | |
end | |
end |
This file contains hidden or 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
post "products/show" => "products#show", :as => :product_search | |
resources :products |
This file contains hidden or 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
<h1>Listing products</h1> | |
<h2><%= flash[:notice] if flash[:notice].present? %></h2> | |
<%= form_for :product_search, :url => product_search_path do |f| %> | |
Search | |
<%= f.text_field :name %> | |
<% end %> | |
<table> | |
<tr> | |
<th>Name</th> | |
<th>Description</th> | |
<th>Price</th> | |
<th></th> | |
<th></th> | |
<th></th> | |
</tr> | |
<% @products.each do |product| %> | |
<tr> | |
<td><%= product.name %></td> | |
<td><%= product.description %></td> | |
<td><%= product.price %></td> | |
<td><%= link_to 'Show', product %></td> | |
<td><%= link_to 'Edit', edit_product_path(product) %></td> | |
<td><%= link_to 'Destroy', product, confirm: 'Are you sure?', method: :delete %></td> | |
</tr> | |
<% end %> | |
</table> | |
<br /> | |
<%= link_to 'New Product', new_product_path %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment