diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 9eb27226b..df232069b 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -81,6 +81,12 @@ module CommentableActions @search_terms = params[:search] if params[:search].present? end + def set_search_order + if params[:search].present? && params[:order].blank? + params[:order] = 'relevance' + end + end + def set_resource_votes(instance) send("set_#{resource_name}_votes", instance) end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 8a5def88b..e28f053c7 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -4,9 +4,10 @@ class DebatesController < ApplicationController before_action :parse_search_terms, only: :index before_action :parse_tag_filter, only: :index + before_action :set_search_order, only: :index before_action :authenticate_user!, except: [:index, :show] - has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index + has_orders %w{hot_score confidence_score created_at most_commented random relevance}, only: :index has_orders %w{most_voted newest oldest}, only: :show load_and_authorize_resource diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 1be046b7a..cc8a286ec 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -4,9 +4,10 @@ class ProposalsController < ApplicationController before_action :parse_search_terms, only: :index before_action :parse_tag_filter, only: :index + before_action :set_search_order, only: :index before_action :authenticate_user!, except: [:index, :show] - has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index + has_orders %w{hot_score confidence_score created_at most_commented random relevance}, only: :index has_orders %w{most_voted newest oldest}, only: :show load_and_authorize_resource diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 000000000..08d5588ca --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,7 @@ +module OrdersHelper + + def valid_orders + @valid_orders.reject { |order| order =='relevance' && params[:search].blank? } + end + +end \ No newline at end of file diff --git a/app/views/shared/_order_selector.html.erb b/app/views/shared/_order_selector.html.erb index 883205493..e120e98e5 100644 --- a/app/views/shared/_order_selector.html.erb +++ b/app/views/shared/_order_selector.html.erb @@ -1,14 +1,12 @@ -<% # Params: - # - # i18n_namespace: for example "moderation.debates.index" -%> -