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

Commit

Permalink
allow optional inclusion in some controllers + update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
razum2um committed Nov 21, 2014
1 parent 2087940 commit 9a4e097
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ By default parameter keys that are not explicitly permitted will be logged in th

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.

## Partial insclusion

If you won't affect all controllers inherited from `ActionController::Base`,
you can require this gem like this and include it manually

```ruby
gem 'strong_parameters', require: ['strong_parameters/requires']

class SomeController < ActionController::Base
include ActionController::StrongParameters
...
```

## Use Outside of Controllers

While Strong Parameters will enforce permitted and required values in your application controllers, keep in mind
Expand Down
1 change: 0 additions & 1 deletion lib/action_controller/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,3 @@ def params=(val)
end
end

ActiveSupport.on_load(:action_controller) { include ActionController::StrongParameters }
9 changes: 5 additions & 4 deletions lib/strong_parameters.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'action_controller/parameters'
require 'active_model/forbidden_attributes_protection'
require 'strong_parameters/railtie'
require 'strong_parameters/log_subscriber'
require 'strong_parameters/requires'
require 'active_support'

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

5 changes: 5 additions & 0 deletions lib/strong_parameters/requires.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require File.expand_path('../../action_controller/parameters', __FILE__)
require File.expand_path('../../active_model/forbidden_attributes_protection', __FILE__)
require 'strong_parameters/railtie'
require 'strong_parameters/log_subscriber'

0 comments on commit 9a4e097

Please sign in to comment.