Documented hashie_rails.

This commit is contained in:
Maxim Filimonov 2014-06-02 08:39:13 -07:00 committed by dblock
parent 80a8f11a78
commit 41e6c676e1
2 changed files with 6 additions and 16 deletions

View File

@ -236,15 +236,7 @@ p.trick # => NoMethodError
### Mash and Rails 4 Strong Parameters
If you're using [Rails 4 strong parameters](http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters), you will get a [ForbiddenAttributesProtection](https://github.com/rails/strong_parameters/blob/master/lib/active_model/forbidden_attributes_protection.rb) exceptions when mass-assigning attributes.
To allow mass assignment, add the following initializer in config/initializers/mash.rb. This prevents Mash from responding to `:permitted?` and therefore triggering this behavior in [ForbiddenAttributesProtection](https://github.com/rails/strong_parameters/blob/master/lib/active_model/forbidden_attributes_protection.rb).
```ruby
class Mash
include Hashie::Extensions::Mash::ActiveModel
end
```
To enable compatibility with Rails 4 use the ['hashie\_rails' gem](http://rubygems.org/gems/hashie_rails).
## Trash

View File

@ -5,17 +5,15 @@ Upgrading Hashie
#### Compatibility with Rails 4 Strong Parameters
Version 2.1 introduced support to prevent default Rails 4 mass-assignment protection behavior. This was [issue #89](https://github.com/intridea/hashie/issues/89), resolved in [#104](https://github.com/intridea/hashie/pull/104). In version 2.2 this behavior has been removed in [#147](https://github.com/intridea/hashie/pull/147) in favor of a mixin.
Version 2.1 introduced support to prevent default Rails 4 mass-assignment protection behavior. This was [issue #89](https://github.com/intridea/hashie/issues/89), resolved in [#104](https://github.com/intridea/hashie/pull/104). In version 2.2 this behavior has been removed in [#147](https://github.com/intridea/hashie/pull/147) in favor of a mixin and extracted into a separate gem in 3.0.
To enable 2.1 compatible behavior, add the following initializer in config/initializers/mash.rb. This prevents Mash from responding to `:permitted?` and therefore triggering this behavior in [ForbiddenAttributesProtection](https://github.com/rails/strong_parameters/blob/master/lib/active_model/forbidden_attributes_protection.rb).
To enable 2.1 compatible behavior, use the ['hashie\_rails' gem](http://rubygems.org/gems/hashie_rails).
```ruby
class Mash
include Hashie::Extensions::Mash::ActiveModel
end
```bash
gem 'hashie_rails'
```
See [Mash and Rails 4 Strong Parameters](README.md#mash-and-rails-4-strong-parameters) for more details.
See [#154](https://github.com/intridea/hashie/pull/154) and [Mash and Rails 4 Strong Parameters](README.md#mash-and-rails-4-strong-parameters) for more details.
#### Key Conversions in Hashie::Dash and Hashie::Trash