Created
December 5, 2016 02:58
-
-
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.
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
# 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