No commit activity in last 3 years
No release in over 3 years
params_sanitizer sanitize parameter.It is really easy and useful.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0

Runtime

 Project Readme

ParamsSanitizer

params_sanitizer sanitize parameter.It is really easy and useful.

Installation

Add this line to your application's Gemfile:

gem 'params_sanitizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install params_sanitizer

Usage

For example. sanitize params for a search query.

Define sanitizer.

class SearchParamsSanitizer < ParamsSanitizer::Base
  def self.permit_filter
    [:word, :order]
  end

  exist_value  :word,  ''               # set default value '', when param[:word] does not exist.
  accept_value :order, 1 , ['0','1']    # set default value 1, when param[:order] is not 0 or 1.
end

other sanitizer look this. ParamsSanitizer::Sanitizers

and in controller

def search_params
  SearchParamsSanitizer.sanitize(params)  # can get sanitized params.
end

result.

{
  word: 'japanese anime',
  unknown_params: 'hogehogehoge',
}

# after sanitize

{
  word: 'japanese anime',
  order: 1
}

when params nest.

{
  search: { word: 'japanese anime' }
}
def search_params
  SearchParamsSanitizer.sanitize(params, :search)  # can get sanitized params.
end

result.

{
  word: 'japanese anime',
  order: 1
}

Sanitizers

API DOCUMENT

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request