0.0
No commit activity in last 3 years
No release in over 3 years
A better way to operate on Rails params.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

CleanParams

Clean Params is a Ruby gem for use with Rails to access the controller parameters cleanly. No more ugly hash accesses. No more flooding your codebase with multiple condition checking. With clean_params you can specify various rules to parse your params hash inside the initializer file. It also allows for nested hash parsing.

Installation

Add this line to your application's Gemfile:

gem 'clean_params'

Run the generator to create the initializer file. You can specify your parsing rules here.

rails g clean_params:install

Usage

Example initializer file -

CleanParams.configure do |config|
  config.params = {
    # Customize your params here
    'key' => [['key', 'Key'], 'default'],
	'key2' => [['key2', 'Key2'], 'key2']
  }
end

Example params hash -

params = {"utf8"=>"✓", "authenticity_token"=>"123", "Key" => "key", "token"=>"323344", "customer_detail"=>{"caller_id"=>"123", "customer_name"=>"XYZ"}}

And goodies -

params = CleanParams.clean(params) # params - rails params hash
params.key # => key
params.key2 # => key2
params.token # => 323344
params.caller_id # => 123

Or you can include it inside the filter in ApplicationController and use the object inside any controller.

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