###Part 1: Review Time 20 min
###Part 2: Search! Time: 90min
- Create a search box in index.html.erb
<%= form_tag "/", method: "GET" do %>
<%= text_field_tag :q, params[:q] %>
<%= submit_tag "Search" %>
<% end %>
- Add to index method - extend index action to handle a search param
def index
@shirts = Shirt.search_for(params[:q])
end
- See what happens when we run this! ERROR!
- Create a method on the Model to get our records passed in from search box
def self.search_for(query)
where('name LIKE :query OR description LIKE :query', query: "%#{query}%")
end
- Display search results in the search.html.erb
<% @shirts.each do |shirt| %>
<section>
<header><%= shirt.name %></header>
<p><%= shirt.description %></p>
<%= image_tag shirt.image %>
</section>
<% end %>