1class Admin::SearchesController < Admin::AdminController |
|
2 def show |
|
3 if petition_search? |
|
4 redirect_to admin_petitions_url(search_params)
|
|
5 elsif signature_search? |
|
6 redirect_to admin_signatures_url(search_params)
|
|
7 else |
|
8 redirect_to admin_root_url, notice: "Sorry, we didn't understand your query" |
|
9 end |
|
10 end |
|
12 private
|
|
14 def petition_search? |
|
15 params[:type] == "petition" |
|
16 end |
|
18 def signature_search? |
|
19 params[:type] == "signature" |
|
20 end |
|
22 def search_params |
|
23 if petition_search? |
|
24 if params[:match] == "none" |
|
25 params.slice(:q, :match) |
|
26 elsif params[:tags].present? |
|
27 params.slice(:q, :tags, :match) |
|
28 else |
|
29 params.slice(:q) |
|
30 end |
|
31 elsif signature_search? |
|
32 params.slice(:q, :window) |
|
33 else |
|
34 {}
|
|
35 end |
|
36 end |
|
37end |