query_humanize_attribute.patch

Dmitry Lisichkin, 2021-05-13 12:37

Download (937 Bytes)

View differences:

app/models/query.rb
202 202
  def initialize(field, options)
203 203
    @field = field.to_s
204 204
    @options = options
205
    @options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
206 205
    # Consider filters with a Proc for values as remote by default
207 206
    @remote = options.key?(:remote) ? options[:remote] : options[:values].is_a?(Proc)
208 207
  end
......
674 673
  # Adds an available filter
675 674
  def add_available_filter(field, options)
676 675
    @available_filters ||= ActiveSupport::OrderedHash.new
676

  
677
    field_name = field.gsub(/_id$/, '')
678
    options[:name] ||= l(options[:label], default: queried_class.human_attribute_name(field_name))
679
    
677 680
    @available_filters[field] = QueryFilter.new(field, options)
678 681
    @available_filters
679 682
  end