Skip to content

Instantly share code, notes, and snippets.

@kellylougheed
Created December 5, 2016 02:58
Show Gist options
  • Save kellylougheed/409aff38a788c23020705581f392682d to your computer and use it in GitHub Desktop.
Save kellylougheed/409aff38a788c23020705581f392682d to your computer and use it in GitHub Desktop.
Creates a dropdown menu to search for examples by the literary device they illustrate.
# Dropdown search for examples categorized by their device
<%= form_tag(examples_path, :method => "get") do %>
<%= select("example", "device", Example.all.map{ |e| e.device }.uniq.sort, selected: 'alliteration') %>
<%= submit_tag "Go!" %>
<% end %>
# The home page checks to see if a device has been selected in the dropdown search, and shows examples of that device if so
def index
if params[:example]
@examples = Example.where(device: params[:example][:device].downcase).paginate(:page => params[:page], :per_page => 10)
@query = params[:example][:device]
else
@examples = Example.all.paginate(:page => params[:page], :per_page => 10)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment