Rename filter method to filter_by
Ruby 2.6 introduces `Enumerable#filter` as an alias to `Enumerable#select`, and so our Filterable.filter method will not work with Ruby 2.6. So we're renaming the method to `filter_by`, which is similar to `find_by`. We could also change the `filter` method so if a block is given it delegates to `Enumerable#filter`, the same way ActiveRecord handles the `select` method, but IMHO this is easier to follow.
This commit is contained in:
@@ -9,7 +9,7 @@ module CommentableActions
|
||||
|
||||
@resources = @current_order == "recommendations" && current_user.present? ? @resources.recommendations(current_user) : @resources.for_render
|
||||
@resources = @resources.search(@search_terms) if @search_terms.present?
|
||||
@resources = @advanced_search_terms.present? ? @resources.filter(@advanced_search_terms) : @resources
|
||||
@resources = @advanced_search_terms.present? ? @resources.filter_by(@advanced_search_terms) : @resources
|
||||
|
||||
@resources = @resources.page(params[:page]).send("sort_by_#{@current_order}")
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ class Budget
|
||||
investments = investments.send(current_filter) if current_filter.present?
|
||||
investments = investments.by_heading(params[:heading_id]) if params[:heading_id].present?
|
||||
investments = investments.search(params[:search]) if params[:search].present?
|
||||
investments = investments.filter(params[:advanced_search]) if params[:advanced_search].present?
|
||||
investments = investments.filter_by(params[:advanced_search]) if params[:advanced_search].present?
|
||||
investments
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module Filterable
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def filter(params)
|
||||
def filter_by(params)
|
||||
resources = all
|
||||
params.each do |filter, value|
|
||||
if allowed_filter?(filter, value)
|
||||
|
||||
Reference in New Issue
Block a user