Action Dispatch 静态文件
此中间件从磁盘提供静态文件,如果可用。如果找不到文件,它将转交给主应用程序。
在 Rails 应用程序中,此中间件配置为从 public/
目录提供资产。
仅提供 GET 和 HEAD 请求。POST 和其他 HTTP 方法将转交给主应用程序。
仅提供根目录中的文件;拒绝路径遍历。
方法
类公共方法
new(app, path, index: "index", headers: {}) 链接
源代码: 显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/static.rb, line 19 def initialize(app, path, index: "index", headers: {}) @app = app @file_handler = FileHandler.new(path, index: index, headers: headers) end
实例公共方法
call(env) 链接
源代码: 显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/static.rb, line 24 def call(env) @file_handler.attempt(env) || @app.call(env) end