Skip to content
This repository was archived by the owner on Aug 17, 2017. It is now read-only.

Commit a9e97d9

Browse files
committed
allow optional inclusion in some controllers + update readme
1 parent e012729 commit a9e97d9

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ By default parameter keys that are not explicitly permitted will be logged in th
8585

8686
Additionally, this behaviour can be changed by changing the `config.action_controller.action_on_unpermitted_parameters` property in your environment files. If set to `:log` the unpermitted attributes will be logged, if set to `:raise` an exception will be raised.
8787

88+
## Partial insclusion
89+
90+
If you won't affect all controllers inherited from `ActionController::Base`,
91+
you can require this gem like this and include it manually
92+
93+
```ruby
94+
gem 'strong_parameters', require: ['strong_parameters/requires']
95+
96+
class SomeController < ActionController::Base
97+
include ActionController::StrongParameters
98+
...
99+
```
100+
88101
## Use Outside of Controllers
89102

90103
While Strong Parameters will enforce permitted and required values in your application controllers, keep in mind

lib/action_controller/parameters.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,3 @@ def params=(val)
265265
end
266266
end
267267

268-
ActiveSupport.on_load(:action_controller) { include ActionController::StrongParameters }

lib/strong_parameters.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require 'action_controller/parameters'
2-
require 'active_model/forbidden_attributes_protection'
3-
require 'strong_parameters/railtie'
4-
require 'strong_parameters/log_subscriber'
1+
require 'strong_parameters/requires'
2+
require 'active_support'
3+
4+
ActiveSupport.on_load(:action_controller) { include ActionController::StrongParameters }
5+

lib/strong_parameters/requires.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require File.expand_path('../../action_controller/parameters', __FILE__)
2+
require File.expand_path('../../active_model/forbidden_attributes_protection', __FILE__)
3+
require 'strong_parameters/railtie'
4+
require 'strong_parameters/log_subscriber'
5+

0 commit comments

Comments
 (0)