RailsConditionalParams
This gem patches ActionController::Parameters
to support conditional
parameters—parameters that are permitted only if some condition is true.
Basically, it ensures that any hash key passed to permit()
with true
as
its value is made into a permitted key, while keys passed with false
or nil
are ignored.
It is compatible with Rails 4.2 and later, including Rails 5.
Installation
Add this line to your application's Gemfile:
gem 'rails_conditional_params'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_conditional_params
Usage
params.permit(:title, :body, published: admin?)
# published will only be permitted if admin? returns true
Contributing
- Fork it ( https://github.com/brentdax/rails_conditional_params/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request