{"id":14955992,"url":"https://github.com/roberts1000/format_restricter_rails","last_synced_at":"2026-01-06T13:05:08.907Z","repository":{"id":47904475,"uuid":"58511919","full_name":"roberts1000/format_restricter_rails","owner":"roberts1000","description":"A Rails Engine that prevents Rails controllers from processing undesired formats","archived":false,"fork":false,"pushed_at":"2024-06-03T05:28:53.000Z","size":124,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T17:48:35.232Z","etag":null,"topics":["rails-engine","ruby-gem","ruby-on-rails"],"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/roberts1000.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"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":"2016-05-11T03:37:17.000Z","updated_at":"2024-06-30T20:35:19.000Z","dependencies_parsed_at":"2024-06-03T05:34:22.369Z","dependency_job_id":"ae4d9069-ec9e-438d-a56e-2f3c266d33f8","html_url":"https://github.com/roberts1000/format_restricter_rails","commit_stats":{"total_commits":47,"total_committers":1,"mean_commits":47.0,"dds":0.0,"last_synced_commit":"4bce3fc0efc48478492b6e00df969f9aa233f030"},"previous_names":["corlewsolutions/format_restricter_rails"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberts1000%2Fformat_restricter_rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberts1000%2Fformat_restricter_rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberts1000%2Fformat_restricter_rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberts1000%2Fformat_restricter_rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roberts1000","download_url":"https://codeload.github.com/roberts1000/format_restricter_rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245535515,"owners_count":20631298,"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":["rails-engine","ruby-gem","ruby-on-rails"],"created_at":"2024-09-24T13:12:08.724Z","updated_at":"2026-01-06T13:05:08.848Z","avatar_url":"https://github.com/roberts1000.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# format_restricter_rails\n\n`format_restricter_rails` provides a simple way to block Ruby on Rails controller actions from processing unsupported formats. If you've seen the following type of errors on your production site, `format_restricter_rails` can help:\n\n```ruby\nActionView::MissingTemplate (Missing template tasks/index, application/index with {:locale=\u003e[:en], :formats=\u003e[:json], :variants=\u003e[], :handlers=\u003e[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}\n```\n\nWhy do these errors occur? If it's not a bug in the app code, it's usually because a person, or a bot, is sending requests to your app in a format you didn't anticipate. \n\nWhen this happens, you could start defining `respond_to` calls in your actions to handle the new formats. Once you realize that's going to explode your code base, you might try to call `respond_to :html`, at the top of your controller class, in hopes that it will help. Sadly, it won't. That's where format_restricter_rails comes in. It provides a single controller class method called `restrict_formats_to` that does exactly what you want. When unallowed formats are requested, the controller halts execution and returns **HTTP Error 406 Not acceptable**.\n\n## Versioning Scheme\n\nReleases are versioned using [SemVer 2.0.0](https://semver.org/spec/v2.0.0.html) with the following caveats:\n\n1. Support for a Ruby version, that reaches EOL, is removed in a major or minor release.\n1. Support for a Ruby on Rails version, that reaches EOL, is removed in a major or minor release.\n\n## Supported Ruby Versions\n\nRuby 3.1+\n\n## Supported Ruby on Rails Versions\n\nRails 7.1+\n\n## Installation\n\nAdd this line to your Rails application's Gemfile:\n\n```ruby\ngem 'format_restricter_rails'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\nAdd `restrict_formats_to` to the top of a controller to restrict all actions in the controller to the specified format(s).\n\n#### Example 1: Restrict all actions\n\n````ruby\nclass MySnazzyController \u003c ApplicationController\n  restrict_formats_to :html, :json\n\n  def my_action_1\n  end\n\n  def my_action_2\n  end\nend\n````\n\nYou can also use `only:` and `except:` options to target specific actions.\n\n\n#### Example 2: Using the `only:` option\n\n````ruby\nclass MySnazzyController \u003c ApplicationController\n  restrict_formats_to :html, only: :my_action_1\n  restrict_formats_to :json, only: [:my_action_2, :my_action_3]\n\n  def my_action_1\n  end\n\n  def my_action_2\n  end\n\n  def my_action_3\n  end\nend\n````\n\n#### Example 2: Using the `except:` Option\n\n````ruby\nclass MySnazzyController \u003c ApplicationController\n  restrict_formats_to :html, except: :my_action_1\n\n  def my_action_1\n  end\n\n  def my_action_2\n  end\nend\n````\n\n## Contributing\n\nBug reports and pull requests are welcome on the format_restricter_rails [issues](https://github.com/roberts1000/format_restricter_rails/issues) page.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberts1000%2Fformat_restricter_rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froberts1000%2Fformat_restricter_rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberts1000%2Fformat_restricter_rails/lists"}