Sinatra将cache_control设置为公共文件夹中的静态文件编译错误

发布于 2024-12-28 23:22:25 字数 385 浏览 2 评论 0原文

我不知道为什么,但当我设置此设置时,它无法编译

设置:static_cache_control,[:public,:max_age => 300]

这就是我得到的,


syntax error, unexpected tASSOC, expecting ']' (SyntaxError)
  set :static_cache_control, [:public, :max_age => 300]
                                                  ^


我只想为 css、javaascript 和图像文件设置“expires”标头。

谢谢。

I'm not sure why but when I set this setting it can't compile


set :static_cache_control, [:public, :max_age => 300]

This is what I get


syntax error, unexpected tASSOC, expecting ']' (SyntaxError)
  set :static_cache_control, [:public, :max_age => 300]
                                                  ^


I just want to set "expires" header to css, javaascript and image files.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2025-01-04 23:22:25

我猜您使用的是 Ruby 1.8.7。 Sinatra 文档中显示的语法(将数组中的最后一个条目转换为哈希值)似乎是在 Ruby 1.9 中引入的,但在 1.8.7 中并未引入。

尝试用大括号显式包裹哈希条目 {}:(

set :static_cache_control, [:public, {:max_age => 300}]

或升级 Ruby。)

I'm guessing you're using Ruby 1.8.7. It seems that the syntax shown in the Sinatra docs, where the last entry in an array is converted to a hash, was introduced in Ruby 1.9 and isn't in 1.8.7.

Try explicitly wrapping the hash entries with braces {}:

set :static_cache_control, [:public, {:max_age => 300}]

(Or upgrade Ruby.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文