24.3 Active Resources 21.2 Form Helpers
curl --silent --head http://localhost:3000/
HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "69a4bd000017d6b64ee99e8c96c85e94"
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Date: Fri, 29 Jun 2012 16:38:08 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
X-Runtime: 0.363776
Content-Length: 0
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _depot_session=BAh7CCIQX2NzcmZfdG9rZW4iMTdRQldodXhsRHRwY3J1K1JoYlBGZXVxUUhibDQwakxOL0tnOWdWdW1sMWc9Ig9zZXNzaW9uX2lkIiU1ZmM0ZmZjNjg4MDBhMzU1Yzk2MzVkOWFmNWFkYTRmNiIMY2FydF9pZGkP--2468557541029b3a34a77a70986d5289d559b714; path=/; HttpOnly
add a method to return the latest product
edit app/models/product.rb
set ETAG and LastModified headers on the response
edit app/controllers/store_controller.rb
class StoreController < ApplicationController
skip_before_filter :authorize
def index
if params[:set_locale]
redirect_to store_path(:locale => params[:set_locale])
else
@products = Product.order(:title)
@cart = current_cart
end
latest = Product.latest
fresh_when :etag => latest, :last_modified => latest.created_at.utc
expires_in 10.minutes, :public => true
end
end
curl --silent --head http://localhost:3000/
HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "4f35a2d75ed51caf73b533c55bb65a7b"
Last-Modified: Fri, 29 Jun 2012 16:29:59 GMT
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Date: Fri, 29 Jun 2012 16:38:08 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
X-Runtime: 0.263011
Content-Length: 0
Cache-Control: max-age=600, public
Set-Cookie: _depot_session=BAh7CCIQX2NzcmZfdG9rZW4iMXJ0REdoWDgvdmNYOWczT2o0MjVtWHA2N05sOVE1eDRXL3IxMk1aUksvSjQ9Ig9zZXNzaW9uX2lkIiU0YmNhNTk0ZTIxNGI4MTgxYmFiMGQzNTk0ZDViMDFlOCIMY2FydF9pZGkQ--3f328f0f08af96485ba8e2d1ecec09bd5163efa8; path=/; HttpOnly
curl --silent --head http://localhost:3000/ -H 'If-None-Match: "4f35a2d75ed51caf73b533c55bb65a7b"'
HTTP/1.1 304 Not Modified
X-Ua-Compatible: IE=Edge
Etag: "4f35a2d75ed51caf73b533c55bb65a7b"
Last-Modified: Fri, 29 Jun 2012 16:29:59 GMT
Date: Fri, 29 Jun 2012 16:38:09 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
X-Runtime: 0.200204
Cache-Control: max-age=600, public
Set-Cookie: _depot_session=BAh7ByIPc2Vzc2lvbl9pZCIlMDc4MzJkZmY0ODlhYmZhNTgwZDlhNWU4MjhmYzljMDMiDGNhcnRfaWRpEg%3D%3D--14deb02d2b2a4245bc48b411501a31e946cd2e26; path=/; HttpOnly
curl --silent --head http://localhost:3000/ -H 'If-Modified-Since: Fri, 29 Jun 2012 16:29:59 GMT'
HTTP/1.1 304 Not Modified
X-Ua-Compatible: IE=Edge
Etag: "4f35a2d75ed51caf73b533c55bb65a7b"
Last-Modified: Fri, 29 Jun 2012 16:29:59 GMT
Date: Fri, 29 Jun 2012 16:38:09 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
X-Runtime: 0.316443
Cache-Control: max-age=600, public
Set-Cookie: _depot_session=BAh7ByIPc2Vzc2lvbl9pZCIlYTBhYmI4MWU1ZThjMzE1ZjgwMDczMWNhMzk0MmZiYjAiDGNhcnRfaWRpEw%3D%3D--8ab0ebdc7e555809adaed833970a39e623a1b413; path=/; HttpOnly
curl --silent --head http://localhost:3000/
HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "4f35a2d75ed51caf73b533c55bb65a7b"
Last-Modified: Fri, 29 Jun 2012 16:29:59 GMT
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Date: Fri, 29 Jun 2012 16:38:19 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
X-Runtime: 0.358029
Content-Length: 0
Cache-Control: max-age=600, public
Set-Cookie: _depot_session=BAh7CCIQX2NzcmZfdG9rZW4iMVVrOVJtRm1UellMOVhKbDVoWGN1Vk1vRzA1UFF0S1VZaDJTRy82SnFMcXM9Ig9zZXNzaW9uX2lkIiU1NzFhOTA3NjRkNGQyMTkzNDQ4MzhiMjEwZWI3NmI2MyIMY2FydF9pZGkV--1ea44146c13f97deb09427d89e653f4c2913b720; path=/; HttpOnly
curl --silent --head http://localhost:3000/ -H 'If-None-Match: "4f35a2d75ed51caf73b533c55bb65a7b"'
HTTP/1.1 304 Not Modified
X-Ua-Compatible: IE=Edge
Etag: "4f35a2d75ed51caf73b533c55bb65a7b"
Last-Modified: Fri, 29 Jun 2012 16:29:59 GMT
Date: Fri, 29 Jun 2012 16:38:20 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
X-Runtime: 0.276510
Cache-Control: max-age=600, public
Set-Cookie: _depot_session=BAh7ByIPc2Vzc2lvbl9pZCIlYTI2Mzk4NWI2MTc3YjNjYjI1MzY3MzU0NTY5ZWNiMmMiDGNhcnRfaWRpFw%3D%3D--8053bf328257af1fa5ebc489c77e0b96795ca13b; path=/; HttpOnly