{"id":18318425,"url":"https://github.com/tether/ensure_param_exists","last_synced_at":"2025-09-10T08:11:50.492Z","repository":{"id":10941158,"uuid":"13248432","full_name":"tether/ensure_param_exists","owner":"tether","description":"Provide an easy way to verify you're receiving the correct parameters in an API request.","archived":false,"fork":false,"pushed_at":"2015-05-19T15:52:24.000Z","size":208,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-09T14:08:52.919Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/PetroFeed/ensure_param_exists","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/tether.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-01T15:58:19.000Z","updated_at":"2015-05-20T15:39:43.000Z","dependencies_parsed_at":"2022-09-23T10:41:00.389Z","dependency_job_id":null,"html_url":"https://github.com/tether/ensure_param_exists","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tether/ensure_param_exists","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tether%2Fensure_param_exists","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tether%2Fensure_param_exists/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tether%2Fensure_param_exists/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tether%2Fensure_param_exists/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tether","download_url":"https://codeload.github.com/tether/ensure_param_exists/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tether%2Fensure_param_exists/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260249957,"owners_count":22980763,"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":[],"created_at":"2024-11-05T18:09:32.411Z","updated_at":"2025-06-16T22:05:05.960Z","avatar_url":"https://github.com/tether.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ensure_param_exists\n\nProvide an easy way to verify you're receiving the correct parameters in an API request in Rails.\n\nAt PetroFeed we found that we were repeatedly writing the following code in our controllers:\n\n```ruby\nclass ArticleController\n  before_filter :ensure_title_exists\n\n  private\n\n    def ensure_title_exists\n      return unless params[:title].blank?\n      render json: { success: false, message: \"missing title parameter\" }, status: 422\n    end\nend\n```\n\nTo keep our controllers DRY we created the `ensure_param` gem which allows us to do the following:\n\n\n```ruby\nclass ArticleController\n  ensure_param :title\nend\n```\n\nClassy! Cut that duplicate code and keep your controllers DRY! :hocho:\n\nInstallation\n----\n\n```ruby\ngem install ensure_param_exists\n```\n\nUsage\n----\n\nAdd ensure_param_exists to your gemfile:\n\n```ruby\ngem 'ensure_param_exists'\n```\n\nMixin the functionality into a controller (or base controller):\n\n```ruby\nclass ArticleController\n  include EnsureParamExists\n\n  # ...\nend\n```\n\nDefine any parameters that you'd like check to make sure they exist with \n`ensure_param`, `ensure_any_params`, or `ensure_all_params`. The singular method takes a \nsymbol, plurals take a symbol array, and any options at the end are passed to `before_filter`:\n\n\n```ruby\nclass ArticleController\n  include EnsureParamExists\n\n  # Make sure title exists\n  ensure_param :title, only: [:show]\n\n  # Make sure title or author exists\n  ensure_any_params :title, :author, only: [:show]\n  \n  # Make sure title and author exists\n  ensure_all_params :title, :author, except: [:index]\nend\n```\n\n## Copyright\n\nCopyright (c) 2013 PetroFeed. See [LICENSE](https://github.com/PetroFeed/ensure_param_exists/blob/master/LICENSE) for further details.\n\n---\n\nProudly brought to you by [PetroFeed](http://PetroFeed.com).\n\n![Pedro](https://www.petrofeed.com/img/company/pedro.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftether%2Fensure_param_exists","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftether%2Fensure_param_exists","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftether%2Fensure_param_exists/lists"}