{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/18374","labels_url":"https://api.github.com/repos/rails/rails/issues/18374/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/18374/comments","events_url":"https://api.github.com/repos/rails/rails/issues/18374/events","html_url":"https://github.com/rails/rails/pull/18374","id":53581259,"number":18374,"title":"Accept a collection in fresh_when and stale?","user":{"login":"claudiob","id":10076,"avatar_url":"https://avatars.githubusercontent.com/u/10076?v=3","gravatar_id":"","url":"https://api.github.com/users/claudiob","html_url":"https://github.com/claudiob","followers_url":"https://api.github.com/users/claudiob/followers","following_url":"https://api.github.com/users/claudiob/following{/other_user}","gists_url":"https://api.github.com/users/claudiob/gists{/gist_id}","starred_url":"https://api.github.com/users/claudiob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claudiob/subscriptions","organizations_url":"https://api.github.com/users/claudiob/orgs","repos_url":"https://api.github.com/users/claudiob/repos","events_url":"https://api.github.com/users/claudiob/events{/privacy}","received_events_url":"https://api.github.com/users/claudiob/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-07T00:16:36Z","updated_at":"2015-02-11T07:23:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/18374","html_url":"https://github.com/rails/rails/pull/18374","diff_url":"https://github.com/rails/rails/pull/18374.diff","patch_url":"https://github.com/rails/rails/pull/18374.patch"},"body":"The methods `fresh_when` and `stale?` from `ActionController::ConditionalGet` accept a single record as a short form for a hash ([see docs](http://api.rubyonrails.org/classes/ActionController/ConditionalGet.html)). For instance:\r\n\r\n```ruby\r\n  def show\r\n    @article = Article.find(params[:id])\r\n    fresh_when(@article)\r\n  end\r\n```\r\n\r\nis just a short form for:\r\n\r\n```ruby\r\n  def show\r\n    @article = Article.find(params[:id])\r\n    fresh_when(etag: @article, last_modified: @article.created_at)\r\n  end\r\n```\r\n\r\nThis commit extends `fresh_when` and `stale?` to also accept a collection of records, so that a short form similar to the one above can be used in an `index` action. \r\nAfter this commit, the following code:\r\n\r\n```ruby\r\ndef index\r\n  @article = Article.all\r\n  fresh_when(etag: @articles, last_modified: @articles.maximum(:created_at))\r\nend\r\n```\r\n\r\ncan be simply written as:\r\n\r\n```ruby\r\ndef index\r\n  @article = Article.all\r\n  fresh_when(@articles)\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/73842385","html_url":"https://github.com/rails/rails/pull/18374#issuecomment-73842385","issue_url":"https://api.github.com/repos/rails/rails/issues/18374","id":73842385,"user":{"login":"kaspth","id":350807,"avatar_url":"https://avatars.githubusercontent.com/u/350807?v=3","gravatar_id":"","url":"https://api.github.com/users/kaspth","html_url":"https://github.com/kaspth","followers_url":"https://api.github.com/users/kaspth/followers","following_url":"https://api.github.com/users/kaspth/following{/other_user}","gists_url":"https://api.github.com/users/kaspth/gists{/gist_id}","starred_url":"https://api.github.com/users/kaspth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaspth/subscriptions","organizations_url":"https://api.github.com/users/kaspth/orgs","repos_url":"https://api.github.com/users/kaspth/repos","events_url":"https://api.github.com/users/kaspth/events{/privacy}","received_events_url":"https://api.github.com/users/kaspth/received_events","type":"User","site_admin":false},"created_at":"2015-02-11T07:23:54Z","updated_at":"2015-02-11T07:23:54Z","body":"Looks good."}}