Ruby on rails A按哈希属性列出的顶级事件

Ruby on rails A按哈希属性列出的顶级事件,ruby-on-rails,ruby,activerecord,rails-activerecord,ahoy,Ruby On Rails,Ruby,Activerecord,Rails Activerecord,Ahoy,我试图找到一种正确的方法,根据事件中的特定属性(“值”)获取数据库中前5个(按计数)事件。我也在使用hightop gem,使其更容易获得前5名 如果我使用: Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top(:name, 5) 这是可行的,但按事件名称排序。我想按事件中存在的“价值”属性进行排序。以下是典型事件的情况: <Ahoy::Event id: 229, vis

我试图找到一种正确的方法,根据事件中的特定属性(“值”)获取数据库中前5个(按计数)事件。我也在使用hightop gem,使其更容易获得前5名

如果我使用:

Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top(:name, 5)
这是可行的,但按事件名称排序。我想按事件中存在的“价值”属性进行排序。以下是典型事件的情况:

<Ahoy::Event id: 229, visit_id: 318, user_id: 1, name: "Thing", properties: {"episode"=>"1", "title"=>"Test", "value"=>"Thing Ep 1: Test"}, time: "2017-11-02 11:34:10">
以及:

Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top("properties ->> 'value'", 5)

但这会产生以下错误:“无法为类型文本下标,因为它不是数组”。有什么方法可以真正做到我想要的吗?

删除双引号可行吗?没有,这会产生语法错误:
语法错误,意外的tSTRING\u BEG,期望关键字\u do\u LAMBDA或tLAMBEG\u of u month)。top(properties->'value',5,nil:false)
您是否运行了
rails生成ahoy:stores:active\u record
?这是postgresql中特定的内容。sql可能很有用,包括从服务器生成的sql以及所有详细信息和sql标记……是的,生成器是在安装后运行的。
Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top("properties ->> 'value'", 5)