Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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 on rails 我';我正在尝试加载中间件?_Ruby On Rails_Ruby_Middleware - Fatal编程技术网

Ruby on rails 我';我正在尝试加载中间件?

Ruby on rails 我';我正在尝试加载中间件?,ruby-on-rails,ruby,middleware,Ruby On Rails,Ruby,Middleware,我正在尝试为RubyonRails应用程序编写一些中间件。以下是我所拥有的: app/middleware/update_cache.rb: class UpdateCache def initialize(app) @app = app end def call(env) @app.call(env) end end config/application.rb: require File.expand_path("../boot", __FILE__) re

我正在尝试为RubyonRails应用程序编写一些中间件。以下是我所拥有的:

app/middleware/update_cache.rb:

class UpdateCache
  def initialize(app)
    @app = app
  end

  def call(env)
    @app.call(env)
  end
end
config/application.rb:

require File.expand_path("../boot", __FILE__)
require "rails/all"
Bundler.require(*Rails.groups)

module MyApp
  class Application < Rails::Application
    config.middleware.use("UpdateCache")
  end
end

app/middlewhere/update_cache.rb是放置UpdateCache的正确位置吗?我做错了什么?

您的应用程序中可能还有另一个类(或它的依赖项之一)名为
UpdateCache
,rails正在使用该类


为了验证这一点,您可以删除这个UpdateCache类,并尝试从rails控制台中计算
UpdateCache
——如果这不会引发错误,那么您就已经找到了罪魁祸首

你的问题有答案。对我来说,这听起来像是另一个名为UpdateCache的类在跟踪你的(可能来自你的应用程序、另一个gem等)@user3762171:我看到了那篇文章,但据我所知,我会逐字跟随他们的建议。你有什么建议?@Frederickhung:天哪,就是这样!哇,我可能会在这上面呆上一段时间。提交回复,我会将其标记为正确答案!
undefined method `call' for #<UpdateCache:0x00000003eec1b0>
/home/fred/my_app/config/application.rb:7:in `<class:Application>': uninitialized constant MyApp::Application::UpdateCache (NameError)
    from /home/fred/my_app/config/application.rb:11:in `<module:MyApp>'
    from /home/fred/my_app/config/application.rb:10:in `<top (required)>'
    from /home/fred/.gem/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /home/fred/.gem/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /home/fred/.gem/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /home/fred/.gem/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /home/fred/.gem/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/fred/.gem/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:8:in `require'
    from bin/rails:8:in `<main>'