我想使用戶註冊等的(每天)使用chartkick,它是一個簡單的一行代碼的數量的線圖,但它是給一個錯誤未定義的方法`group_by_day」 - 軌道3.2
`undefined method `group_by_day' for #<Class:0x00000004b4fbf0>`
在我的意見我有
<%= line_chart User.group_by_day(:created_at).count %>
錯誤日誌:
Rendered admin/dashboards/index.html.erb within layouts/application (145.2ms)
Completed 500 Internal Server Error in 1018ms
NoMethodError - undefined method `group_by_day' for #<Class:0x00000004b4fbf0>:
activerecord (3.2.14) lib/active_record/dynamic_matchers.rb:55:in `method_missing'
app/views/admin/dashboards/index.html.erb:38:in `_app_views_admin_dashboards_index_html_erb___3330517857505238097_39214860'
actionpack (3.2.14) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.14) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.14) lib/action_view/template.rb:143:in `render'
actionpack (3.2.14) lib/action_view/renderer/template_renderer.rb:48:in `block (2 levels) in render_template'
actionpack (3.2.14) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.14) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.14) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.14) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.14) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
非常感謝,我檢查了寶石,這是我失蹤。 – ben
但有一些我不明白,爲什麼不能從另一個表訪問屬性。例如:<%= pie_chart User.city.group(「name」)。count%>,從此我想訪問用戶的城市名稱。不工作,我在這裏做錯了什麼? – ben
@ben我認爲你的意思是計算每個城市的用戶數量,可能你可以嘗試'User.includes(:city).group(「city.name」)。count' – Mifeng