Sinatra sets cache_control for static files in a common public folder compilation error

I am not sure why, but when I set this parameter, it cannot 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] ^
syntax error, unexpected tASSOC, expecting ']' (SyntaxError) set :static_cache_control, [:public, :max_age => 300] ^ 

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

Thanks.

+4
source share
1 answer

I assume you are using Ruby 1.8.7. It seems that the syntax shown in Sinatra docs, where the last entry in the array is converted to a hash, was introduced in Ruby 1.9 and is not in version 1.8.7.

Try explicitly wrapping the hash entries with curly braces {} :

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

(Or update Ruby.)

+8
source

Source: https://habr.com/ru/post/1392586/


All Articles