Extract concern to handle investments filters

We were defining the same filters in three different controllers. We
were also adding a method in the ApplicationController which only made
sense in the same three controllers.
This commit is contained in:
Javi Martín
2021-03-14 20:56:42 +01:00
parent 313c9eaeba
commit 6bd20ef5ff
5 changed files with 27 additions and 15 deletions

View File

@@ -0,0 +1,17 @@
module InvestmentFilters
extend ActiveSupport::Concern
class_methods do
def investment_filters
%w[not_unfeasible feasible unfeasible unselected selected winners]
end
end
def set_default_investment_filter
if @budget&.balloting? || @budget&.publishing_prices?
params[:filter] ||= "selected"
elsif @budget&.finished?
params[:filter] ||= "winners"
end
end
end