Files
grecia/app/controllers/concerns/has_orders.rb
Javi Martín c3e0a6b089 Remove duplication rendering comments
We were using the same code 5 times, with the only slight variation
being the extra heading in the debates section.
2021-06-27 23:22:00 +02:00

19 lines
553 B
Ruby

module HasOrders
extend ActiveSupport::Concern
attr_reader :valid_orders, :current_order
included do
helper_method :valid_orders, :current_order
end
class_methods do
def has_orders(valid_orders, *args)
before_action(*args) do |c|
@valid_orders = valid_orders.respond_to?(:call) ? valid_orders.call(c) : valid_orders.dup
@valid_orders.delete("relevance") if params[:search].blank?
@current_order = @valid_orders.include?(params[:order]) ? params[:order] : @valid_orders.first
end
end
end
end