Anyone know why I get a syntax error when I try to use curly braces block syntax for Rails.cache.fetch
This errors out with error (syntax error, unexpected ‘{‘, expecting keyword_end (SyntaxError) )
Rails.cache.fetch "person/#{id}" { find(id) }
The following works:
Rails.cache.fetch "person/#{id}" do
find(id)
end
This is because {} has different precedence than do end. In the first expression they are tied to the “person/#{id}” part of the expression.
So your first example is similar to:
while the second is: