У меня ошибка Rails называется: Неизвестный ключ: депозит - PullRequest
0 голосов
/ 05 марта 2019

Я беспокоюсь об этой ошибке, позвонив по номеру Неизвестный ключ: депозит . Хотя я пытался удалить константы, которые не используются в этом фрагменте, хотя я не могу этого сделать, но он все еще жаловался на метод sum в представлении.

Все, что я пытаюсь сделать, - это иметь карту массива, которую я мог бы использовать в представлении, чтобы показать свои результаты.

attribution_helper.rb

module AttributionHelper
  def statistics(events=nil)
    case events
    when Attribution::PARTNER_DASHBOARD_EVENTS
      Attribution::PARTNER_DASHBOARD_EVENTS.map { |event| [ event, (Attribution.attribution_count[event.to_s] || 0), Attribution.onbaording_attribution_stats["#{event}"] || 0] }
    when Attribution::PARTNER_BILLABLE_EVENTS
      array_result = Attribution::PARTNER_BILLABLE_EVENTS.map { |event| [ event, (Attribution.attribution_count[event.to_s] || 0), Attribution.billable_attribution_stats["#{event}"] || 0] }
      ["total", array_result.sum(&:second), array_result.sum(&:third)]
    else
      Attribution::EVENTS.map { |event| [ event, (Attribution.attribution_count[event.to_s] || 0), Attribution.all_attribution_stats["#{event}"] || 0] }
    end
  end
end

attribution.rb модель

include AttributionHelper

VISIT = "visit"
SIGN_UP = "sign_up"
DEPOSIT = "deposit"
WITHDRAW = "withdraw"
ORDER_DONE = "order_done"
ORDER_SUBMIT = "order_submit"
KYC_VERIFIED = "kyc_verified"

EVENTS = [VISIT, SIGN_UP, KYC_VERIFIED, DEPOSIT, WITHDRAW, ORDER_SUBMIT, ORDER_DONE]
PARTNER_DASHBOARD_EVENTS = [VISIT, SIGN_UP]
PARTNER_BILLABLE_EVENTS = [ORDER_DONE, WITHDRAW]

scope :grouped_attribution, -> { self.group(:event) }
scope :attribution_count, -> { grouped_attribution.count }
scope :all_attribution_stats, -> { grouped_attribution.sum(:bonus_amount) }
scope :onbaording_attribution_stats, -> { grouped_attribution.where("event = ? OR event = ?", Attribution::VISIT, Attribution::SIGN_UP).sum(:bonus_amount) }
scope :billable_attribution_stats, -> { grouped_attribution.where("event = ? OR event = ?", Attribution::ORDER_DONE, Attribution::WITHDRAW).sum(:bonus_amount) }

вид

h2.text-center
    code class='text-info' = @price_widget.attribution_channel.statistics(Attribution::PARTNER_DASHBOARD_EVENTS + Attribution::PARTNER_BILLABLE_EVENTS).sum(&:third).to_s(:delimited)

Это результат областей действия:

grouped_attribution.count
   (0.5ms)  SELECT COUNT(*) AS count_all, event AS event FROM `attributions` GROUP BY event
=> {“deposit”=>2, “order_done”=>14, “sign_up”=>10, “visit”=>46, “withdraw”=>2}

grouped_attribution.sum(:bonus_amount)
   (0.6ms)  SELECT SUM(`attributions`.`bonus_amount`) AS sum_bonus_amount, event AS event FROM `attributions` GROUP BY event
=> {“deposit”=>10, “order_done”=>600, “sign_up”=>10000, “visit”=>15000, “withdraw”=>10}

grouped_attribution.where("event = ? OR event = ?", Attribution::VISIT, Attribution::SIGN_UP).sum(:bonus_amount)
   (1.0ms)  SELECT SUM(`attributions`.`bonus_amount`) AS sum_bonus_amount, event AS event FROM `attributions` WHERE (event = ‘visit’ OR event = ‘sign_up’) GROUP BY event
=> {“sign_up”=>10000, “visit”=>15000}

grouped_attribution.where("event = ? OR event = ?", Attribution::ORDER_DONE, Attribution::WITHDRAW).sum(:bonus_amount)
   (1.4ms)  SELECT SUM(`attributions`.`bonus_amount`) AS sum_bonus_amount, event AS event FROM `attributions` WHERE (event = ‘order_done’ OR event = ‘withdraw’) GROUP BY event
=> {“order_done”=>600, “withdraw”=>10}

StackTrace

ArgumentError - Unknown key: deposit:
  activesupport (4.0.12) lib/active_support/core_ext/hash/keys.rb:70:in `block in assert_valid_keys'
  activesupport (4.0.12) lib/active_support/core_ext/hash/keys.rb:69:in `assert_valid_keys'
  activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:18:in `apply_finder_options'
  activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/base.rb:46:in `call'
  activerecord (4.0.12) lib/active_record/scoping/named.rb:163:in `block (2 levels) in scope'
  activerecord (4.0.12) lib/active_record/relation.rb:270:in `scoping'
  activerecord (4.0.12) lib/active_record/scoping/named.rb:163:in `block in scope'
  app/helpers/attribution_helper.rb:10:in `block in statistics'
  app/helpers/attribution_helper.rb:10:in `statistics'
  app/views/price_widgets/dashboard.html.slim:38:in `block in _app_views_price_widgets_dashboard_html_slim___3846780147619711966_70216357117460'
  actionpack (4.0.12) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionpack (4.0.12) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
  actionpack (4.0.12) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  actionpack (4.0.12) lib/action_view/helpers/capture_helper.rb:152:in `content_for'
  app/views/price_widgets/dashboard.html.slim:4:in `_app_views_price_widgets_dashboard_html_slim___3846780147619711966_70216357117460'
  actionpack (4.0.12) lib/action_view/template.rb:143:in `block in render'
  activesupport (4.0.12) lib/active_support/notifications.rb:161:in `instrument'
  actionpack (4.0.12) lib/action_view/template.rb:141:in `render'
  actionpack (4.0.12) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
  actionpack (4.0.12) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (4.0.12) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.12) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.12) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (4.0.12) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
  actionpack (4.0.12) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
  actionpack (4.0.12) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
  actionpack (4.0.12) lib/action_view/renderer/template_renderer.rb:17:in `render'
  actionpack (4.0.12) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionpack (4.0.12) lib/action_view/renderer/renderer.rb:23:in `render'
  actionpack (4.0.12) lib/abstract_controller/rendering.rb:127:in `_render_template'
  actionpack (4.0.12) lib/action_controller/metal/streaming.rb:219:in `_render_template'
  actionpack (4.0.12) lib/abstract_controller/rendering.rb:120:in `render_to_body'
  actionpack (4.0.12) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
  actionpack (4.0.12) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
  actionpack (4.0.12) lib/abstract_controller/rendering.rb:97:in `render'
  actionpack (4.0.12) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.0.12) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  activesupport (4.0.12) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/tiwa/.rbenv/versions/2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
  activesupport (4.0.12) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.0.12) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  actionpack (4.0.12) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  activerecord (4.0.12) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.0.12) lib/action_controller/metal/instrumentation.rb:40:in `render'
  actionpack (4.0.12) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.0.12) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.0.12) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.0.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.0.12) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (4.0.12) lib/active_support/callbacks.rb:483:in `_run__2112368623363193916__process_action__callbacks'
  activesupport (4.0.12) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.12) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.12) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.12) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.12) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.12) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.12) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.12) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.0.12) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.0.12) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.12) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.12) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.12) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.12) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.12) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
  actionpack (4.0.12) lib/action_dispatch/routing/route_set.rb:50:in `call'
  actionpack (4.0.12) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.12) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.12) lib/action_dispatch/routing/route_set.rb:676:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:404:in `call_app!'
  omniauth-identity (1.1.1) lib/omniauth/strategies/identity.rb:43:in `other_phase'
  omniauth (1.2.2) lib/omniauth/strategy.rb:185:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/builder.rb:59:in `call'
  meta_request (0.2.8) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.2.8) lib/meta_request/middlewares/headers.rb:16:in `call'
  meta_request (0.2.8) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  http_accept_language (2.0.1) lib/http_accept_language/middleware.rb:13:in `call'
  simple_captcha2 (0.2.2) lib/simple_captcha/middleware.rb:20:in `call'
  rack (1.5.5) lib/rack/etag.rb:23:in `call'
  rack (1.5.5) lib/rack/conditionalget.rb:35:in `call'
  rack (1.5.5) lib/rack/head.rb:11:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.12) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.12) lib/active_record/migration.rb:373:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.12) lib/active_support/callbacks.rb:373:in `_run__2834334812182002754__call__callbacks'
  activesupport (4.0.12) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.12) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
  bugsnag (6.11.0) lib/bugsnag/integrations/rack.rb:46:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.12) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.12) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.12) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.0.12) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.0.12) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.0.12) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  request_store (1.1.0) lib/request_store/middleware.rb:8:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.5) lib/rack/runtime.rb:17:in `call'
  lib/middleware/security.rb:11:in `call'
  rack (1.5.5) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.12) lib/action_dispatch/middleware/static.rb:84:in `call'
  lib/middleware/i18n_js.rb:9:in `call'
  rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
  rack-cors (1.0.2) lib/rack/cors.rb:97:in `call'
  railties (4.0.12) lib/rails/engine.rb:511:in `call'
  railties (4.0.12) lib/rails/application.rb:97:in `call'
  railties (4.0.12) lib/rails/railtie/configurable.rb:30:in `method_missing'
  rack-reverse-proxy (0.12.0) lib/rack_reverse_proxy/roundtrip.rb:19:in `call'
  rack-reverse-proxy (0.12.0) lib/rack_reverse_proxy/middleware.rb:25:in `call'
  rack (1.5.5) lib/rack/lock.rb:17:in `call'
  rack (1.5.5) lib/rack/content_length.rb:14:in `call'
  rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
...