Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 未定义的方法`按天分组';对于Groupdate+;图表堆栈图_Ruby_Ruby On Rails 3_Rubygems - Fatal编程技术网

Ruby 未定义的方法`按天分组';对于Groupdate+;图表堆栈图

Ruby 未定义的方法`按天分组';对于Groupdate+;图表堆栈图,ruby,ruby-on-rails-3,rubygems,Ruby,Ruby On Rails 3,Rubygems,我试图绘制一个折线图,在创建日期之前按订单显示,我遇到了一个问题 以下是导致错误的my home controller的index.html.erb代码段 <%= line_chart @orders.map { |order| {name: order.id, data: order.created_at.group_by_day(:created_at, default_value: "missing", time_zone: "Kolkata").count} } %>

我试图绘制一个折线图,在创建日期之前按订单显示,我遇到了一个问题

以下是导致错误的my home controller的index.html.erb代码段

<%= line_chart @orders.map { |order|
    {name: order.id, data: order.created_at.group_by_day(:created_at, default_value: "missing", time_zone: "Kolkata").count}
} %>
我的Gemfile中包含了groupdate和chartkick gems,这似乎是常见的修复方法。任何帮助都将不胜感激。如果您需要更多信息,请告诉我

完整跟踪:

app/views/home/index.html.erb:14:in `block in _app_views_home_index_html_erb__895458771_51649740'
activeresource (5.0.0) lib/active_resource/collection.rb:8:in `map'
activeresource (5.0.0) lib/active_resource/collection.rb:8:in `map'
app/views/home/index.html.erb:13:in `_app_views_home_index_html_erb__895458771_51649740'
actionview (5.1.6) lib/action_view/template.rb:157:in `block in render'
activesupport (5.1.6) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.1.6) lib/action_view/template.rb:352:in `instrument_render_template'
actionview (5.1.6) lib/action_view/template.rb:155:in `render'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:52:in `block (2 levels) in render_template'
actionview (5.1.6) lib/action_view/renderer/abstract_renderer.rb:42:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionview (5.1.6) lib/action_view/renderer/abstract_renderer.rb:41:in `instrument'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:51:in `block in render_template'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:50:in `render_template'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.1.6) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.1.6) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (5.1.6) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.1.6) lib/action_controller/metal/renderers.rb:141:in `render_to_body'
actionpack (5.1.6) lib/abstract_controller/rendering.rb:24:in `render'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (5.1.6) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
C:/Ruby24-x64/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
activesupport (5.1.6) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:29:in `cleanup_view_runtime'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (5.1.6) lib/action_controller/metal/implicit_render.rb:33:in `default_render'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `tap'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:108:in `block in run_callbacks'
shopify_app (8.2.6) lib/shopify_app/controller_concerns/login_protection.rb:15:in `shopify_session'
activesupport (5.1.6) lib/active_support/callbacks.rb:117:in `block in run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/builder.rb:63:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.6) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.6.0) lib/web_console/middleware.rb:137:in `call_app'
web-console (3.6.0) lib/web_console/middleware.rb:22:in `block in call'
web-console (3.6.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.6.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
puma (3.11.3) lib/puma/configuration.rb:225:in `call'
puma (3.11.3) lib/puma/server.rb:624:in `handle_request'
puma (3.11.3) lib/puma/server.rb:438:in `process_client'
puma (3.11.3) lib/puma/server.rb:302:in `block in run'
puma (3.11.3) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
打印时的订单示例:

#<ShopifyAPI::Order:0x00000000086f6780 @attributes={"id"=>380632137775, "email"=>"", "closed_at"=>nil, "created_at"=>"2018-04-12T22:01:52-04:00", "updated_at"=>"2018-04-12T22:01:52-04:00", "number"=>2, "note"=>"", "token"=>"hidden", "gateway"=>nil, "test"=>false, "total_price"=>"0.00", "subtotal_price"=>"0.00", "total_weight"=>0, "total_tax"=>"0.00", "taxes_included"=>false, "currency"=>"USD", "financial_status"=>"paid", "confirmed"=>true, "total_discounts"=>"0.00", "total_line_items_price"=>"0.00", "cart_token"=>nil, "buyer_accepts_marketing"=>false, "name"=>"#1002", "referring_site"=>nil, "landing_site"=>nil, "cancelled_at"=>nil, "cancel_reason"=>nil, "total_price_usd"=>"0.00", "checkout_token"=>nil, "reference"=>nil, "user_id"=>10752655407, "location_id"=>6268256303, "source_identifier"=>nil, "source_url"=>nil, "processed_at"=>"2018-04-12T22:01:52-04:00", "device_id"=>nil, "phone"=>nil, "customer_locale"=>nil, "app_id"=>1354745, "browser_ip"=>nil, "landing_site_ref"=>nil, "order_number"=>1002, "discount_codes"=>[], "note_attributes"=>[], "payment_gateway_names"=>[], "processing_method"=>"manual", "checkout_id"=>nil, "source_name"=>"shopify_draft_order", "fulfillment_status"=>nil, "tax_lines"=>[], "tags"=>"", "contact_email"=>nil, "order_status_url"=>"hidden", "line_items"=>[#<ShopifyAPI::LineItem:0x000000000866fc58 @attributes={"id"=>783789817903, "variant_id"=>7469149978671, "title"=>"Product #1", "quantity"=>1, "price"=>"0.00", "sku"=>"", "variant_title"=>nil, "vendor"=>"new-vision-nutritio-dev", "fulfillment_service"=>"manual", "product_id"=>639214125103, "requires_shipping"=>true, "taxable"=>true, "gift_card"=>false, "name"=>"Product #1", "variant_inventory_management"=>nil, "properties"=>[], "product_exists"=>true, "fulfillable_quantity"=>1, "grams"=>0, "total_discount"=>"0.00", "fulfillment_status"=>nil, "tax_lines"=>[#<ShopifyAPI::TaxLine:0x000000000865dcb0 @attributes={"title"=>"NJ State Tax", "price"=>"0.00", "rate"=>0.06625}, @prefix_options={}, @persisted=true>]}, @prefix_options={}, @persisted=true>], "shipping_lines"=>[], "fulfillments"=>[], "refunds"=>[]}, @prefix_options={}, @persisted=true> 
380632137775,“email”=>,“closed”=>nil,“created”=>“2018-04-12T22:01:52-04:00”,“updated”=>“2018-04-12T22:01:52-04:00”,“number”=>2,“note”=>,“token”=>“hidden”,“gateway”=>nil,“test”=>false,“total”=>“total”=>0.00”,“subtotal”=>“u price”=>“0.00”,“总U重量”=>0”,“总U税”=>0”,“包括美元”=>,“财务状况”=>“已支付”、“已确认”=>“真实”、“总折扣”=>“0.00”、“总商品价格”=>“0.00”、“购物代币”=>零、“买家接受营销”=>假、“姓名”=>“1002”、“参考网站”=>零、“登陆网站”=>零、“取消原因”=>零、“总价格”=>“0.00”、“结帐代币”=>零、“参考用户”=>零“=>10752655407,”位置id=>6268256303,“源标识符”=>nil,“源url=>nil”,处理时间为“=>”2018-04-12T22:01:52-04:00”,“设备id=>nil”,“电话”=>nil,“客户区域设置”=>nil,“应用id”=>1354745,“浏览器ip=>nil”,“登陆站点参考”=>nil,“订单号”=>1002,“折扣代码”=>,“备注属性”[]>,[]>,“处理方法”=>“手动”、“结帐id”=>零、“来源名称”=>“shopify\u草稿订单”、“履行状态”=>零、“税行”=>[]、“标签”=>、“联系人电子邮件”=>零、“订单状态url”=>“隐藏”、“行项目”=>[\f36783789817903、“变体id”=>746914978671、“产品”=>“数量”=>1、“价格”=>“0.00”、“变体标题”=>零。”供应商“=>”新愿景营养品开发“,”履行服务“=>”手册“,”产品id“=>639214125103,“要求装运”=>真实“,”应税“=>真实“,”礼品卡“=>假“,”名称“=>”产品1“,”变体库存管理“=>零”,“属性”=>[],”产品存在“=>真实“,”可履行数量“=>1”,“克”=>0“,”总折扣“=>”0.00”,“履行状态”“=>零、”税号“=>[”新泽西州税“=>”、”价格“=>”0.00“、”费率“=>0.06625}、@prefix_选项={}、@persisted=true>]}、@prefix_选项={}、@persisted=true>]、”船运线=>[]、”履行“=>[]、”退款“=>[]、@prefix_选项={}、@persisted=true>

如果查看
groupdate
的文档,
groupby\u day
方法用于对象集合,而不是特定属性

以下代码适用于订单数组:

<%=  
  line_chart @orders.group_by_day(default_value: "missing", time_zone: "Kolkata") { |order|
  order.created_at
}.map { |date, orders| [date, orders.size] }
%>


groupdate
上的文档中,
groupby_day
是一种适用于对象集合(可枚举集合或ActiveRecord集合)的方法。当调用像数组一样的
可枚举对象时,它使用块的返回值来知道要根据对象的哪个属性进行分组,在这种情况下,您的
属性处创建。对
map
的最后一个方法调用将返回
chartkick
可用于渲染折线图的数据,在这种情况下,chartkick需要一个数组,其中包含日期和每个日期的项目计数(或一些聚合值)

如果您查看
groupdate
的文档,
groupby\u day
方法用于对象集合,而不是特定属性

以下代码适用于订单数组:

<%=  
  line_chart @orders.group_by_day(default_value: "missing", time_zone: "Kolkata") { |order|
  order.created_at
}.map { |date, orders| [date, orders.size] }
%>


groupdate
上的文档中,
groupby_day
是一种适用于对象集合(可枚举集合或ActiveRecord集合)的方法。当调用像数组一样的
可枚举对象时,它使用块的返回值来知道要根据对象的哪个属性进行分组,在这种情况下,您的
属性处创建。对
map
的最后一个方法调用将返回
chartkick
可用于渲染折线图的数据,在这种情况下,chartkick需要一个数组,其中包含日期和每个日期的项目计数(或一些聚合值)

问题已创建
\u在
处被视为字符串。您能否向我们提供您的
schema.rb
以确保它是一个时间戳?@LeoCorrea感谢您的回复,我在这里使用Shopify Order API处理我的订单。看起来order.created_at应该返回一个时间戳。让我知道你还需要什么信息,我会尽快把它传过来。所以这些信息不会从数据库中返回?如果它是通过API进行的,并且请求的格式是JSON,那么您必须将字符串转换为ruby中的DateTime对象。查看是什么设置了
@orders
实例会很有用variable@LeoCorrea我已经添加了一个示例,说明其中一个订单在检查时的外观。我还尝试了{name:“order.id”,data:order.created_at.to_datetime.group_by_day(:created_at,default_value:“missing”,time_zone:“Kolkata”).count}并获取以下未定义错误的方法“按天分组”,用于2018年4月12日星期四22:01:52-0400:DateTime在创建问题时将问题视为字符串。您能否向我们提供您的
schema.rb
以确保它是一个时间戳?@LeoCorrea感谢您的回复,我在这里使用Shopify Order API处理我的订单。看起来order.created_at应该返回一个时间戳。让我知道你还需要什么信息,我会尽快把它传过来。所以这些信息不会从数据库中返回?如果它是通过API进行的,并且请求的格式是JSON,那么您必须将字符串转换为ruby中的DateTime对象。查看是什么设置了
@orders
实例会很有用variable@LeoCorrea我已经添加了一个示例,说明了其中一个订单在检查时的外观。我还尝试了{name:“order.id”,data