Revision 0085153c
Added by Ewoud Kohl van Wijngaarden 2 months ago
app/controllers/api/base_controller.rb | ||
---|---|---|
# e.g. /hosts/fqdn/reports # would add host = fqdn to the search bar
|
||
def setup_search_options
|
||
params[:search] ||= ""
|
||
params.keys.each do |param|
|
||
params.each do |param, value|
|
||
if param =~ /(\w+)_id$/
|
||
if params[param].present?
|
||
query = " #{Regexp.last_match(1)} = #{params[param]}"
|
||
if value.present?
|
||
query = " #{Regexp.last_match(1)} = #{value}"
|
||
params[:search] += query unless params[:search].include? query
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #37287 - Iterate on hashes when both key and value are used
This replaces the `hash.keys.each { |k| hash[k] }` and `hash.keys.sort`
patterns with `hash.each { |k, v| }` where it makes sense. This avoids
doing hash lookups when you already know the value anyway.