{"id":15527224,"url":"https://github.com/testdouble/moderate_parameters","last_synced_at":"2025-04-23T12:25:54.857Z","repository":{"id":35134704,"uuid":"177033555","full_name":"testdouble/moderate_parameters","owner":"testdouble","description":"Moderate Parameters Gem","archived":false,"fork":false,"pushed_at":"2023-07-21T20:55:56.000Z","size":218,"stargazers_count":16,"open_issues_count":2,"forks_count":6,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-21T14:03:30.150Z","etag":null,"topics":["hacktoberfest","protected-attributes","rails","strong-parameters","tool","upgrade"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testdouble.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-21T22:31:41.000Z","updated_at":"2024-04-29T20:19:47.000Z","dependencies_parsed_at":"2024-10-02T11:15:01.950Z","dependency_job_id":null,"html_url":"https://github.com/testdouble/moderate_parameters","commit_stats":{"total_commits":125,"total_committers":7,"mean_commits":"17.857142857142858","dds":"0.11199999999999999","last_synced_commit":"77c8148d2ee726c00ad763f6c3c68a25946ad288"},"previous_names":["hintmedia/moderate_params","testdouble/moderate_parameters","hintmedia/moderate_parameters"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fmoderate_parameters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fmoderate_parameters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fmoderate_parameters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fmoderate_parameters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testdouble","download_url":"https://codeload.github.com/testdouble/moderate_parameters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250432422,"owners_count":21429666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","protected-attributes","rails","strong-parameters","tool","upgrade"],"created_at":"2024-10-02T11:05:07.678Z","updated_at":"2025-04-23T12:25:54.830Z","avatar_url":"https://github.com/testdouble.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/4054771/56985278-db1f9280-6b3c-11e9-8719-f48e2ab4885d.png\" alt=\"Moderate Parameters\" background\u003e\n\u003c/p\u003e\n\n\nBy [Hint.io](https://hint.io)\n\n[![Gem Version](https://badge.fury.io/rb/moderate_parameters.svg)](https://badge.fury.io/rb/moderate_parameters) ![CI](https://github.com/hintmedia/moderate_parameters/workflows/CI/badge.svg) ![Appraisals](https://github.com/hintmedia/moderate_parameters/workflows/Appraisals/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/4971eb01d5bd98dbac8b/maintainability)](https://codeclimate.com/github/hintmedia/moderate_parameters/maintainability)\n\nIn our experience with [UpgradeRails](https://www.upgraderails.com), the migration from [protected_attributes](https://github.com/rails/protected_attributes) to [strong_parameters](https://api.rubyonrails.org/classes/ActionController/StrongParameters.html) can leave more questions than answers. It can be difficult to determine what data is originating from within the app and what is coming from the internet.\n\nModerate Parameters is a set of tools providing logging of data sources in the controller by extending `ActionController::Parameters` functionality.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'moderate_parameters'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install moderate_parameters\n\nThen add the initializer by running:\n\n    $ bundle exec rails g moderate_parameters:install\n\nThis will add an initializer to your rails app for turning on/off functionality.\n\n## Usage\n\nGiven a form at `/people/new` that submits data to the `PeopleController#create` action like so:\n\n```ruby\n{ person: { name: 'Kyle', age: '26', height: '180' } }\n```\n\nWith a model that looks like:\n\n```ruby\nclass Person \u003c ActiveRecord::Base\n  attr_accessible :name, :age, :height\n\n  . . .\n\nend\n```\n\nAnd a controller looks like this:\n\n```ruby\nclass PeopleController \u003c ActionController::Base\n  def create\n    Person.create(params[:person])\n  end\n\n  . . .\n\nend\n```\n\nWe can add `moderate_parameters` by following the `strong_parameters` implementation method with a couple slight changes.\n\nAdd a private params method for the controller calling `moderate` (with `controller_name` and `action_name` as the first two args) instead of `permit`:\n\n```ruby\nclass PeopleController \u003c ActionController::Base\n  def create\n    Person.create(person_params) # Was Person.create(params[:person])\n  end\n\n  . . .\n\n  private\n\n    def person_params\n      params.require(:person).moderate(controller_name, action_name, :name)\n    end\nend\n```\n\nThis will cause the `person_params` to flow the same way they did before (getting passed to the model without interruption),\nbut the params that are not included in the argument of `moderate` will be logged to `/log/moderate_params.log`\n\nMeaning that, after submitting the aforementioned data, our `moderate_parameters.log` will look like so:\n\n    people#create Top Level is missing: age\n    people#create Top Level is missing: height\n\nWe can fix this by adding `age` and `height` to `person_params` like so:\n\n```ruby\nclass PeopleController \u003c ActionController::Base\n  def create\n    Person.create(person_params)\n  end\n\n  . . .\n\n  private\n\n    def person_params\n      params.require(:person).moderate(controller_name, action_name, :name, :age, :height)\n    end\nend\n```\n\nWe can then hit submit data from the form at `/people/new` and see that no new lines are added to the `moderate_parameters.log` file.\n\nThis means that we can remove `moderate_parameters` and move to using `permit` as the final migration step of `strong_parameters`:\n\n```ruby\nclass PeopleController \u003c ActionController::Base\n  def create\n    Person.create(person_params)\n  end\n\n  . . .\n\n  private\n\n    def person_params\n      params.require(:person).permit(:name, :age, :height)\n    end\nend\n```\n\nIt is only _**AFTER**_ this final step of the `strong_parameters` migration has been completed that you can safely remove the `protected_attributes` line in the model:\n\n```ruby\nclass Person \u003c ActiveRecord::Base\n  # attr_accessible :name, :age, :height\n\n  . . .\n\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/hintmedia/moderate_parameters. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the moderate_parameters project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hintmedia/moderate_parameters/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdouble%2Fmoderate_parameters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestdouble%2Fmoderate_parameters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdouble%2Fmoderate_parameters/lists"}