rails/rails — pull request #16720 by eladmeidar (2014-08-27 12:45:52+00:00)
Title: Cleaner StrongParameters whitelisting

Ever since SP replaced attr_protected / accessible, I felt a little bit uncomfortable with the additional method it requires you to add to every controller. Since almost all the additional *_params look the same (require + permit something) I created this helper to make it easier to whitelist parameters list for a specific action:

so instead of doing something like this -
```ruby
class UsersController < ActionController

def new
@user = User.new
end

def create

# Here we are using the parameter whitelisting method
@user = User.new(user_params)
if @user.save
redirect_to users_url, notice: "User created"
else
render :new
end
end

private

# Parameter whitelisting method
def user_params
params.require(:user).permit(:name, :age)
end
end
```

this change allows you use the `whitelist_params` method:

```ruby
class UsersController < ApplicationController

filter_parameters create: {user: [:name, :age]}

def create
@user = User.new(create_params) # => create_params is available via BetterStrongParams and the filter_parameters DSL.
if @user.save
redirect_to treasure_url
else
redirect_to jail_url
end
end
end
```

Two things:

1. Not sure I added the method in the right place, under ActionController::Base
2. Tests. feels like I could use a few more ideas.