rails/rails — pull request #17154 by mlarraz (2014-10-03 05:35:27+00:00)
Title: Allow multiple params to be required at once

This is [already supported](https://github.com/rails/strong_parameters#require-multiple-parameters) in Strong Parameters, with the format:

```ruby
params.require(:token)
params.require(:post).permit(:title)
```

However, this can quickly get *very* verbose.

In several situations, I've found myself having to require 10+ parameters on a single controller action, and resorted to adding a private method to `ApplicationController` along the lines of:

```ruby
def require_params(*required)
required.each { |key| params.require(key) }
end
```

By changing `ActionController::Parameters#require` to take an array of keys, iterate over it, and return the last element's value, we preserve the original API while allowing some new patterns to develop.

The original example would instead look like this:
```ruby
params.require(:token, :post).permit(:title)
```

One example of this convenience of is extracting common requirements into an anonymous `before_action`.

Compare
```ruby
before_action do
params.require(:first)
...
params.require(:last)
end
```
with
```ruby
before_action { params.require(:first, ..., :last) }
```
**NOTE:** When multiple required parameters are missing, only the first one will raise `ActionController::ParameterMissing`