Simple rails filters -
i have simplest rails app, scaffold tent
here controller#index
def index @tents = tent @tents = @tents.where(:brand => params[:brand]) if params[:brand] @tents = @tents.where(:season => params[:season]) if params[:season] end
view standart, generated scaffold
and here search witch should filter data
= form_tag tents_path, method: :get = label_tag "manufacturer" = select_tag :brand, options_for_select(...), include_blank: true = label_tag "seasons" - tent.pluck(:season).each |season| =check_box_tag 'season', season =h season = submit_tag 'submit'
problem 1:
when submit from, , params unselected(select or checl_boxes) don't want send params sent empty
get /tents?utf8=...&brand=&season=&commit=submit
problem 2:
when check multiple checkboxes request somthing like
get /tents?utf8=...&brand=brand
&season=4&season=3&commit=submit
after expect data selected both values, controller expected both values in field, , returns 0 results
any suggestuions?
update
probably question solved in railscasts-111 (advanced search form)
about problem 2: need specify season checkbox below:
=check_box_tag 'season[]', season
but didnt test it
Comments
Post a Comment