I have page that list the trails and provides a text based search - see current version here http://ift.tt/1uZA194. I'm adding a form to filter the results of the search e.g. by difficulty, activities, length, allows dogs, etc. I have the filter working, but it's not loading the previously used params in the checkbox fields where the user can select multiple items e.g. allows biking, allows hiking etc. after a search. It's currently only loading the param for the greatest value. e.g. if I have params difficulty=0&difficulty=1&difficulty2 it will only load the page with difficulty 2 selected.
Specifically the :travel_type (radio), :difficulty (checkbox), :dogs (checkbox) and :action_types (checkbox) are having the issue.
Here is a sample URL with params http://localhost:3000/trails?utf8=%E2%9C%93&travel_type=on&max_time=168&max_distance=35&difficulty=0&difficulty=1&difficulty=2&dogs=1&dogs=2&action_types=1&action_types=2&action_types=3&commit=Filter
On reload travel_type 2 was selected difficulty 2 was selected dogs 2 was selected action_types 3 was selected
Here is my view code written in slim
.page
section.search
.row
form.form-inputs.columns.large-6.large-offset-1#search-form action=trails_path method='get'
input type='search' placeholder='Search' name='query_string'
button.button-search
i.sprite-icon-search
section.filter
.row
= form_tag nil, method: :get, class: 'form-inputs columns large-11 large-offset-1', id: 'trail-filter-form' do
.estimate_time
strong Estimate time using
ul
li
= radio_button_tag :travel_type, params[:travel_type], 0
= label_tag 'Hiking'
li
= radio_button_tag :travel_type, params[:travel_type], 1
= label_tag 'Running'
li
= radio_button_tag :travel_type, params[:travel_type], 2
= label_tag 'Biking'
div.max_time
strong Max Time
div.time
p
= '30m'
= range_field_tag :max_time, params[:max_time], in: 30..240
= '4+ hours'
p
strong Max Distance
div.distance
p
= '1mi '
= range_field_tag :max_distance, params[:max_distance], in: 1..50
= '50+ mi'
div.difficulty
strong Difficulty
div
p
= check_box_tag :difficulty, 0, params[:difficulty] == '0'
= label_tag
i class='sprite-icon-difficulty-0'
= check_box_tag :difficulty, 1, params[:difficulty] == '1'
= label_tag
i class='sprite-icon-difficulty-1'
= check_box_tag :difficulty, 2, params[:difficulty] == '2'
= label_tag
i class='sprite-icon-difficulty-2'
p
strong Dogs
div
= check_box_tag :dogs, 0, params[:dogs] == '0'
= label_tag 'Off Leash'
= check_box_tag :dogs, 1, params[:dogs] == '1'
= label_tag 'w/Leash'
= check_box_tag :dogs, 2, params[:dogs] == '2'
= label_tag 'Not Allowed'
div.views
strong Views
div
= check_box_tag :views, 1, params[:views] == '1'
= label_tag 'Has Views'
p
strong Activities Allowed
div
= check_box_tag :action_types, 0, params[:action_types] == '0'
= label_tag
i class='sprite-icon-horseback-med'
= check_box_tag :action_types, 1, params[:action_types] == '1'
= label_tag
i class='sprite-icon-ski-med'
= check_box_tag :action_types, 2, params[:action_types] == '2'
= label_tag
i class='sprite-icon-hiking-med'
= check_box_tag :action_types, 3, params[:action_types] == '3'
= label_tag
i class='sprite-icon-bike-med'
= submit_tag 'Submit', value: 'Filter', class: 'button small right trail-filter'
section.content#trails-find
.row.find-trails-map
.large-11.large-offset-1.columns
.map#find-map
= render 'trails/trail_list', locals: { decorated_trails: decorated_trails,
title: 'PUBLIC TRAILS' }
Aucun commentaire:
Enregistrer un commentaire