From a7929c607d5d2d5c9777eff9ae25e3e33e32aa84 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 28 Aug 2015 20:07:45 +0200 Subject: [PATCH] adds a helper to simplify the way selects and filters are rendered --- app/helpers/application_helper.rb | 6 ++++++ app/views/admin/comments/index.html.erb | 2 +- app/views/admin/debates/index.html.erb | 2 +- app/views/admin/organizations/index.html.erb | 2 +- app/views/admin/users/index.html.erb | 2 +- app/views/debates/index.html.erb | 4 ++-- app/views/moderation/comments/index.html.erb | 2 +- app/views/moderation/debates/index.html.erb | 2 +- app/views/shared/_locale_switcher.html.erb | 2 +- 9 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 69cb06d45..77afc1317 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,4 +14,10 @@ module ApplicationHelper home_page? ? '' : 'results' end + # if current path is /debates current_path_with_query_params(foo: 'bar') returns /debates?foo=bar + # notice: if query_params have a param which also exist in current path, it "overrides" (query_params is merged last) + def current_path_with_query_params(query_parameters) + url_for(request.query_parameters.merge(query_parameters)) + end + end diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb index 941e1e9ed..87178c66b 100644 --- a/app/views/admin/comments/index.html.erb +++ b/app/views/admin/comments/index.html.erb @@ -8,7 +8,7 @@
<%= t("admin.comments.index.filters.#{filter}") %>
<% else %>
<%= link_to t("admin.comments.index.filters.#{filter}"), - admin_comments_path(filter: filter) %>
+ current_path_with_query_params(filter: filter) %> <% end %> <% end %> diff --git a/app/views/admin/debates/index.html.erb b/app/views/admin/debates/index.html.erb index cdeb7b016..9ac89b5e1 100644 --- a/app/views/admin/debates/index.html.erb +++ b/app/views/admin/debates/index.html.erb @@ -8,7 +8,7 @@
<%= t("admin.debates.index.filters.#{filter}") %>
<% else %>
<%= link_to t("admin.debates.index.filters.#{filter}"), - admin_debates_path(filter: filter) %>
+ current_path_with_query_params(filter: filter) %> <% end %> <% end %> diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index df003e6f8..8569d0c47 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -21,7 +21,7 @@
<%= t("admin.organizations.index.filters.#{filter}") %>
<% else %>
<%= link_to t("admin.organizations.index.filters.#{filter}"), - admin_organizations_path(filter: filter) %>
+ current_path_with_query_params(filter: filter) %> <% end %> <% end %> diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 8f728295d..b6f3f1cfe 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -8,7 +8,7 @@
<%= t("admin.users.index.filters.#{filter}") %>
<% else %>
<%= link_to t("admin.users.index.filters.#{filter}"), - admin_users_path(filter: filter) %>
+ current_path_with_query_params(filter: filter) %> <% end %> <% end %> diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 71266aeb2..701110af3 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -16,7 +16,7 @@ <% @valid_orders.each do |order| %> <% end %> diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb index f9c95e9be..da2bb8251 100644 --- a/app/views/moderation/comments/index.html.erb +++ b/app/views/moderation/comments/index.html.erb @@ -8,7 +8,7 @@
<%= t("moderation.comments.index.filters.#{filter}") %>
<% else %>
<%= link_to t("moderation.comments.index.filters.#{filter}"), - moderation_comments_path(filter: filter) %>
+ current_path_with_query_params(filter: filter) %> <% end %> <% end %> diff --git a/app/views/moderation/debates/index.html.erb b/app/views/moderation/debates/index.html.erb index cbd6baa5d..8fb013605 100644 --- a/app/views/moderation/debates/index.html.erb +++ b/app/views/moderation/debates/index.html.erb @@ -8,7 +8,7 @@
<%= t("moderation.debates.index.filters.#{filter}") %>
<% else %>
<%= link_to t("moderation.debates.index.filters.#{filter}"), - moderation_debates_path(filter: filter) %>
+ current_path_with_query_params(filter: filter) %> <% end %> <% end %> diff --git a/app/views/shared/_locale_switcher.html.erb b/app/views/shared/_locale_switcher.html.erb index f76a71b9c..763acc4b9 100644 --- a/app/views/shared/_locale_switcher.html.erb +++ b/app/views/shared/_locale_switcher.html.erb @@ -4,7 +4,7 @@