我在 Rails 4.2 应用程序中使用 Ahoy gem。Ahoy Events 存储具有许多文本属性和一个properties
包含我要查询的数据的属性的事件。例如,这是我通过 rails 控制台返回的最后一个事件
>> Ahoy::Event.last
Ahoy::Event Load (3.8ms) SELECT "ahoy_events".* FROM "ahoy_events" ORDER BY "ahoy_events"."id" DESC LIMIT 1
=> #<Ahoy::Event id: "fffff17f-44e6-41d7-9c32-fa895338f54e", visit_id: "6b05b1ca-3863-46da-9c48-a3ab5fa4a9ee", user_id: 1, name: "$click", properties: {"tag"=>"a", "page"=>"/conversations/2", "text"=>"View", "href"=>"/conversations/2"}, time: "2015-08-23 13:25:51">
我将如何检索 properties['text'] = 'View' 的所有事件
我努力了Ahoy::Event.where(:properties['text'] => 'View').count
返回:```
Ahoy::Event.where(:properties['text'] => 'View').count NoMethodError: undefined method
to_sym' for nil:NilClass from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/sanitization.rb:59:in
block in expand_hash_conditions_for_aggregates'来自/Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0 /gems/activerecord-4.2.5.1/lib/active_record/sanitization.rb:58:ineach' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/sanitization.rb:58:in
expand_hash_conditions_for_aggregates' 来自 /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1 /lib/active_record/relation/query_methods.rb:957:build_where' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation/query_methods.rb:584:in
在哪里!来自/Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation/query_methods.rb:574:inwhere' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/querying.rb:10:in
哪里'来自(irb):13来自/Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:instart' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in
从 /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:inconsole' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in
run_command 开始' 来自 /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in<top (required)>' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in
来自 /Users/dariusgoore/development/ blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:inblock in require' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in
load_dependency' 来自 /Users/dariusgoore/development/blackops/.bundle/gems/ruby /2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:inrequire' from /Users/dariusgoore/development/blackops/bin/rails:8:in
'来自 /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:inload' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in
block in load' 来自 /Users/dariusgoore /development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:inload_dependency' from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in
load' 来自 /Users/dariusgoore/.rubies/ruby-2.2。 1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Users/dariusgoore/.rubies/ruby-2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in
需要'```
我在网上查找了查询哈希属性但没有成功。非常感谢任何指导。