Is it possible to use stale?
with a collection? For example, I'm developing a REST api that will allow the client to occasionally query the server to ask for the most up-to-date list of items. It would be nice if stale?
could check a collection against my If-Modified.. header and send a 304 if nothing has changed.
Quick example:
def index
@items = Item.all
if stale?(@items)
render json: @items
end
end
def show
if stale?(@item)
render json: @item
end
end
For Rails < 5:
stale?(last_modified: @items.maximum(:updated_at))
For Rails >= 5 just:
stale?(@items)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With