README.md in hightop-0.2.1 vs README.md in hightop-0.2.2

- old
+ new

@@ -2,28 +2,21 @@ A nice shortcut for group count queries ```ruby Visit.top(:browser) +# { +# "Chrome" => 63, +# "Safari" => 50, +# "Firefox" => 34 +# } ``` -instead of +Works with Active Record, Mongoid, arrays and hashes -```ruby -Visit.group(:browser).where("browser IS NOT NULL").order("count_all DESC, browser").count -``` +[![Build Status](https://travis-ci.org/ankane/hightop.svg?branch=master)](https://travis-ci.org/ankane/hightop) -Be sure to [sanitize user input](https://rails-sqli.org/) like you must with `group` - -Also works with arrays and hashes - -```ruby -["up", "up", "down"].top(1) -``` - -[![Build Status](https://travis-ci.org/ankane/hightop.svg)](https://travis-ci.org/ankane/hightop) - ## Installation Add this line to your application’s Gemfile: ```ruby @@ -64,9 +57,22 @@ And min count ```ruby Visit.top(:city, min: 10) +``` + +## User Input + +If passing user input as the column, be sure to sanitize it first [like you must](https://rails-sqli.org/) with `group`. + +```ruby +column = params[:column] + +# check against permitted columns +raise "Unpermitted column" unless ["column_a", "column_b"].include?(column) + +User.top(column) ``` ## Arrays and Hashes Arrays