1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib
claudiob 050fda0206 Accept a collection in fresh_when and stale?
The methods `fresh_when` and `stale?` from ActionController::ConditionalGet
accept a single record as a short form for a hash. For instance

```ruby
  def show
    @article = Article.find(params[:id])
    fresh_when(@article)
  end
```

is just a short form for:

```ruby
  def show
    @article = Article.find(params[:id])
    fresh_when(etag: @article, last_modified: @article.created_at)
  end
```

This 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. After this commit, the following code:

```ruby
def index
  @article = Article.all
  fresh_when(etag: @articles, last_modified: @articles.maximum(:created_at))
end
```

can be simply written as:

```ruby
def index
  @article = Article.all
  fresh_when(@articles)
end
```
2015-02-10 17:08:44 -08:00
..
abstract_controller Use public Module#include, in favor of https://bugs.ruby-lang.org/issues/8846 2015-01-31 23:12:41 -05:00
action_controller Accept a collection in fresh_when and stale? 2015-02-10 17:08:44 -08:00
action_dispatch Explicitly ignored wildcard verbs from head_routes 2015-02-08 12:03:56 -05:00
action_pack Start Rails 5 development 🎉 2014-11-28 15:00:06 -02:00
abstract_controller.rb No need for .rb extension 2013-08-25 11:39:09 +02:00
action_controller.rb Add ActionController::Renderer 2015-01-22 01:02:11 +03:00
action_dispatch.rb Update copyright notices to 2015 [ci skip] 2014-12-31 08:34:14 +01:00
action_pack.rb Update copyright notices to 2015 [ci skip] 2014-12-31 08:34:14 +01:00