我有一个Rails应用程序,我想使用ChartKick在"Dashbaord"页面上显示一些图表 . 我安装了ChartKick,我知道我需要使用MongoDB查询来提取数据,但是我想要提取的数据和"count"是嵌套密钥,在我的主索引视图中,我通过创建新模型和使用 embeds_one
和 embedded_in
将嵌套信息拉入主模型 .
我现在仍然试图将这个嵌套信息放入饼图中 .
我的模型如下: -
class Vulnerability
include Mongoid::Document
field :id, type: String
field :type, type: String
field :description, type: String
field :published, type: String
field :modified, type: String
field :href, type: String
embeds_one :cvss
end
二级模型:
class Cvss
include Mongoid::Document
field :score, type: Integer
field :vector, type: String
embedded_in :vulnerability
end
这意味着我可以在索引视图中使用 <td><%= vulnerability.cvss.score %></td>
来获取'Score'的值
我的仪表板视图为空白,除了一些渲染的共享布局和饼图的以下代码: <%= pie_chart Vulnerability.collection.aggregate("$group" => { "score" => "$name", count: {"$sum" => 1}}) %>
这给出了错误 no implicit conversion of Symbol into Integer
Mongo文档存储如下:
{
"_id" : "CESA-2017:3081",
"_index" : "bulletins",
"_score" : null,
"sort" : [
103042
],
"lastseen" : "2017-10-30T20:42:09",
"references" : [
"https://access.redhat.com/errata/RHSA-2017:3081"
],
"affectedPackage" : [
{
"OS" : "CentOS",
"OSVersion" : "7",
"packageVersion" : "7.0.76-3.el7_4",
"arch" : "noarch",
"packageFilename" : "",
"packageName" : "",
"operator" : "lt"
},
],
"description" : "",
"edition" : 1,
"reporter" : "CentOS Project",
"published" : "2017-10-30T11:36:20",
"title" : "tomcat security update",
"type" : "centos",
"enchantments" : {
},
"bulletinFamily" : "unix",
"cvelist" : [
],
"modified" : "",
"id" : "",
"href" : "",
"cvss" : {
"score" : 6.8,
"vector" : "AV:NETWORK/AC:MEDIUM/Au:NONE/C:PARTIAL/I:PARTIAL/A:PARTIAL/"
}
}
我已经从Mongo文档中删除了一些信息以便于阅读,因为我没有使用这些键/信息,但它们是从另一个应用程序插入的 .
我的开发日志显示以下内容:
Started GET "/admin" for 127.0.0.1 at 2017-11-23 13:13:01 +0000
Processing by Admin::ApplicationController#index as HTML
User Load (31.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Rendering admin/application/index.html.erb within admin/layouts/admin
Rendered admin/application/index.html.erb within admin/layouts/admin (5.2ms)
Completed 500 Internal Server Error in 161ms (ActiveRecord: 31.3ms)
TypeError - no implicit conversion of Symbol into Integer:
app/views/admin/application/index.html.erb:4:in `_app_views_admin_application_index_html_erb__448509050785199124_47309549846040'
Started POST "/__better_errors/760bcb2acc441dc3/variables" for 127.0.0.1 at 2017-11-23 13:13:01 +0000