Rails面板的问题



我在Rails应用程序中使用chrome扩展Rails Panel。但是它不能正常工作。

Gemfile

group :development do
  gem 'therubyracer', :platforms => :ruby
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
end

开发日志:

Errno::ENOENT - No such file or directory - /home/rahulv/sprint/S33/tmp/data/meta_request/d927421bce3c90bc465c9ceb894813ca.json:
  meta_request (0.3.4) lib/meta_request/storage.rb:16:in `read'
  meta_request (0.3.4) lib/meta_request/middlewares/meta_request_handler.rb:20:in `events_json'
  meta_request (0.3.4) lib/meta_request/middlewares/meta_request_handler.rb:11:in `call'
  pdfkit (0.5.4) lib/pdfkit/middleware.rb:16:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.16) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.16) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.16) lib/active_support/callbacks.rb:405:in `_run__572592932466143201__call__1542018980761186849__callbacks'
  activesupport (3.2.16) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.16) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.16) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.16) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  better_errors (2.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.0) lib/better_errors/middleware.rb:57:in `call'
  rack-contrib (1.2.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/headers.rb:16:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.16) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.16) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.16) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.16) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.16) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.16) lib/action_dispatch/middleware/static.rb:63:in `call'
  railties (3.2.16) lib/rails/engine.rb:484:in `call'
  railties (3.2.16) lib/rails/application.rb:231:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.16) lib/rails/rack/log_tailer.rb:17:in `call'
  thin (1.5.1) lib/thin/connection.rb:81:in `block in pre_process'
  thin (1.5.1) lib/thin/connection.rb:79:in `pre_process'
  thin (1.5.1) lib/thin/connection.rb:54:in `process'
  thin (1.5.1) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.5.1) lib/thin/backends/base.rb:63:in `start'
  thin (1.5.1) lib/thin/server.rb:159:in `start'
  rack (1.4.5) lib/rack/handler/thin.rb:13:in `run'
  rack (1.4.5) lib/rack/server.rb:268:in `start'
  railties (3.2.16) lib/rails/commands/server.rb:70:in `start'
  railties (3.2.16) lib/rails/commands.rb:55:in `block in <top (required)>'
  railties (3.2.16) lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:6:in `<main>'

有什么问题吗?

我已经通过以下步骤解决了这个问题:

  1. 删除/tmp/data/
  2. 中的meta_request文件夹
  3. 使用rails s
  4. 重启服务器

现在一切正常:)

由于RailsPanel是一个伟大的工具,继续使用它与meta_request gem在文件config/initializers/meta_request.rb中创建Rails初始化器,代码如下:

if defined?(MetaRequest) && MetaRequest::Event.private_instance_methods(false).exclude?(:not_encodable?)
  MetaRequest::Event.class_eval do
    private
    def json_encodable(payload)
      return {} unless payload.is_a?(Hash)
      transform_hash(payload, deep: true) do |hash, key, value|
        if value.class.to_s == 'ActionDispatch::Http::Headers'
          value = value.to_h.select { |k, _| k.upcase == k }
        elsif not_encodable?(value)
          value = self.class.const_get(:NOT_JSON_ENCODABLE)
        end
        begin
          value.to_json(methods: [:duration])
          new_value = value
        rescue StandardError
          new_value = self.class.const_get(:NOT_JSON_ENCODABLE)
        end
        hash[key] = new_value
      end.with_indifferent_access
    end
    def not_encodable?(value)
      (defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)) ||
        (defined?(ActionDispatch) &&
          (value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response)))
    end
  end
end

参考:https://github.com/dejan/rails_panel/pull/177 issuecomment - 797378347

我能够"修复";这是通过移除机架微型分析器gem来实现的。

相关内容

  • 没有找到相关文章

最新更新