rails/rails — pull request #8597 by sferik (2012-12-24 07:59:06+00:00)
Title: Add support for action arguments

On this Festivus day—the fourth anniversary of [the announcement of the merger of Merb into Rails](http://weblog.rubyonrails.org/2008/12/23/merb-gets-merged-into-rails-3/)—I'd like to reintroduce one of my favorite features from Merb that never made it into Rails 3: action arguments. This feature gives users the ability to define controller actions with parameters that take the values of keys in the `params` hash of the same name. For example:

```ruby
class PostsController < ApplicationController

# Without action arguments
def destroy
@post = Post.find(params[:id])
@post.destroy
end

# With action arguments
def destroy(id)
@post = Post.find(id)
@post.destroy
end

end
```

In my opinion, this syntax is more concise, more Ruby-like, and more explicit than fetching values out of a big `params` hash (of course, `params` is still there for users who need it…as is the whole `request` object).

I believe this feature pairs particularly nicely with the introduction of strong parameters in Rails 4, since specifying an action argument is also a shorthand for specifying a required parameter.

In Merb, which supported Ruby 1.8, the implementation of this feature required some black magic. Today, this feature can be implemented cleanly using the `Method#parameters`, which was added to Ruby 1.9 for just this purpose.