[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8064":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":27,"readmeContent":28,"aiSummary":29,"trendingCount":16,"starSnapshotCount":16,"syncStatus":30,"lastSyncTime":31,"discoverSource":32},8064,"responders","heartcombo\u002Fresponders","heartcombo","A set of Rails responders to dry up your application","",null,"Ruby",2057,155,28,3,0,11,28.58,"MIT License",false,"main",[23,24,25,26],"controllers","flash-messages","rails","ruby","2026-06-12 02:01:48","# Responders\n\n[![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Fresponders.svg)](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Fresponders)\n\nA set of responders modules to dry up your Rails app.\n\n## Installation\n\nAdd the responders gem to your Gemfile:\n\n    gem \"responders\"\n\nUpdate your bundle and run the install generator:\n\n    $ bundle install\n    $ rails g responders:install\n\nIf you are including this gem to support backwards compatibility for responders in previous releases of Rails, you only need to include the gem and bundle.\n\n    $ bundle install\n\n## Responders Types\n\n### FlashResponder\n\nSets the flash based on the controller action and resource status.\nFor instance, if you do: `respond_with(@post)` on a POST request and the resource `@post`\ndoes not contain errors, it will automatically set the flash message to\n`\"Post was successfully created\"` as long as you configure your I18n file:\n\n```yaml\n  flash:\n    actions:\n      create:\n        notice: \"%{resource_name} was successfully created.\"\n      update:\n        notice: \"%{resource_name} was successfully updated.\"\n      destroy:\n        notice: \"%{resource_name} was successfully destroyed.\"\n        alert: \"%{resource_name} could not be destroyed.\"\n```\n\nIn case the resource contains errors, you should use the failure key on I18n. This is\nuseful to dry up flash messages from your controllers. Note: by default alerts for `update`\nand `destroy` actions are commented in generated I18n file. If you need a specific message\nfor a controller, let's say, for `PostsController`, you can also do:\n\n```yaml\n  flash:\n    posts:\n      create:\n        notice: \"Your post was created and will be published soon\"\n```\n\nThis responder is activated in all non get requests. By default it will use the keys\n`:notice` and `:alert`, but they can be changed in your application:\n\n```ruby\nconfig.responders.flash_keys = [ :success, :failure ]\n```\n\nYou can also have embedded HTML. Just create a `_html` scope.\n\n```yaml\n  flash:\n    actions:\n      create:\n        alert_html: \"\u003Cstrong>OH NOES!\u003C\u002Fstrong> You did it wrong!\"\n    posts:\n      create:\n        notice_html: \"\u003Cstrong>Yay!\u003C\u002Fstrong> You did it!\"\n```\n\nSee also the `namespace_lookup` option to search the full hierarchy of possible keys.\n\n### HttpCacheResponder\n\nAutomatically adds Last-Modified headers to API requests. This\nallows clients to easily query the server if a resource changed and if the client tries\nto retrieve a resource that has not been modified, it returns not_modified status.\n\n### CollectionResponder\n\nMakes your create and update action redirect to the collection on success.\n\n### LocationResponder\n\nThis responder allows you to use callable objects as the redirect location.\nUseful when you want to use the `respond_with` method with\na custom route that requires persisted objects, but the validation may fail.\n\nNote: this responder is included by default, and doesn't need to be included\non the top of your controller (including it will issue a deprecation warning).\n\n```ruby\nclass ThingsController \u003C ApplicationController\n  respond_to :html\n\n  def create\n    @thing = Thing.create(params[:thing])\n    respond_with @thing, location: -> { thing_path(@thing) }\n  end\nend\n```\n\n**Dealing with namespaced routes**\n\nIn order for the LocationResponder to find the correct route helper for namespaced routes you need to pass the namespaces to `respond_with`:\n\n```ruby\nclass Api::V1::ThingsController \u003C ApplicationController\n  respond_to :json\n\n  # POST \u002Fapi\u002Fv1\u002Fthings\n  def create\n    @thing = Thing.create(thing_params)\n    respond_with :api, :v1, @thing\n  end\nend\n```\n\n## Configuring your own responder\n\nResponders only provides a set of modules and to use them you have to create your own\nresponder. After you run the install command, the following responder will be\ngenerated in your application:\n\n```ruby\n# lib\u002Fapplication_responder.rb\nclass ApplicationResponder \u003C ActionController::Responder\n  include Responders::FlashResponder\n  include Responders::HttpCacheResponder\nend\n```\n\nYour application also needs to be configured to use it:\n\n```ruby\n# app\u002Fcontrollers\u002Fapplication_controller.rb\nrequire \"application_responder\"\n\nclass ApplicationController \u003C ActionController::Base\n  self.responder = ApplicationResponder\n  respond_to :html\nend\n```\n\n## Controller method\n\nThis gem also includes the controller method `responders`, which allows you to cherry-pick which\nresponders you want included in your controller.\n\n```ruby\nclass InvitationsController \u003C ApplicationController\n  responders :flash, :http_cache\nend\n```\n\n## Interpolation Options\n\nYou can pass in extra interpolation options for the translation by adding an `flash_interpolation_options` method to your controller:\n\n```ruby\nclass InvitationsController \u003C ApplicationController\n  responders :flash, :http_cache\n\n  def create\n    @invitation = Invitation.create(params[:invitation])\n    respond_with @invitation\n  end\n\n  private\n\n  def flash_interpolation_options\n    { resource_name: @invitation.email }\n  end\nend\n```\n\nNow you would see the message `\"name@example.com was successfully created\"` instead of the default `\"Invitation was successfully created.\"`\n\n## Generator\n\nThis gem also includes a responders controller generator, so your scaffold can be customized\nto use `respond_with` instead of default `respond_to` blocks. From 2.1, you need to explicitly opt-in to use this generator by adding the following to your `config\u002Fapplication.rb`:\n\n```ruby\nconfig.app_generators.scaffold_controller :responders_controller\n```\n\n## Failure handling\n\nResponders don't use `valid?` to check for errors in models to figure out if\nthe request was successful or not, and relies on your controllers to call\n`save` or `create` to trigger the validations.\n\n```ruby\ndef create\n  @widget = Widget.new(widget_params)\n  # @widget will be a valid record for responders, as we haven't called `save`\n  # on it, and will always redirect to the `widgets_path`.\n  respond_with @widget, location: -> { widgets_path }\nend\n```\n\nResponders will check if the `errors` object in your model is empty or not. Take\nthis in consideration when implementing different actions or writing test\nassertions on this behavior for your controllers.\n\n```ruby\ndef create\n  @widget = Widget.new(widget_params)\n  @widget.errors.add(:base, :invalid)\n  # `respond_with` will render the `new` template again,\n  # and set the status based on the configured `error_status`.\n  respond_with @widget\nend\n```\n\n## Verifying request formats\n\n`respond_with` will raise an `ActionController::UnknownFormat` if the request\nMIME type was not configured through the class level `respond_to`, but the\naction will still be executed and any side effects (like creating a new record)\nwill still occur. To raise the `UnknownFormat` exception before your action\nis invoked you can set the `verify_requested_format!` method as a `before_action`\non your controller.\n\n```ruby\nclass WidgetsController \u003C ApplicationController\n  respond_to :json\n  before_action :verify_requested_format!\n\n  # POST \u002Fwidgets.html won't reach the `create` action.\n  def create\n    widget = Widget.create(widget_params)\n    respond_with widget\n  end\nend\n```\n\n## Configuring error and redirect statuses\n\nBy default, `respond_with` will respond to errors on `HTML` & `JS` requests using the HTTP status code `200 OK`,\nand perform redirects using the HTTP status code `302 Found`, both for backwards compatibility reasons.\n\nYou can configure this behavior by setting `config.responders.error_status` and `config.responders.redirect_status` to the desired status codes.\n\n```ruby\nconfig.responders.error_status = :unprocessable_entity\nconfig.responders.redirect_status = :see_other\n```\n\nThese can also be set in your custom `ApplicationResponder` if you have generated one: (see install instructions)\n\n```ruby\nclass ApplicationResponder \u003C ActionController::Responder\n  self.error_status = :unprocessable_entity\n  self.redirect_status = :see_other\nend\n```\n\n_Note_: the application responder generated for new apps already configures a different set of defaults: `422 Unprocessable Entity` for errors, and `303 See Other` for redirects. _Responders may change the defaults to match these in a future major release._\n\n### Hotwire\u002FTurbo and fetch APIs\n\nHotwire\u002FTurbo expects successful redirects after form submissions to respond with HTTP status `303 See Other`, and error responses to be 4xx or 5xx statuses, for example `422 Unprocessable Entity` for displaying form validation errors and `500 Internal Server Error` for other server errors. [Turbo documentation: Redirecting After a Form Submission](https:\u002F\u002Fturbo.hotwired.dev\u002Fhandbook\u002Fdrive#redirecting-after-a-form-submission).\n\nThe example configuration showed above matches the statuses that better integrate with Hotwire\u002FTurbo.\n\n## Examples\n\nWant more examples ? Check out these blog posts:\n\n* [Embracing REST with mind, body and soul](http:\u002F\u002Fblog.plataformatec.com.br\u002F2009\u002F08\u002Fembracing-rest-with-mind-body-and-soul\u002F)\n* [Three reasons to love ActionController::Responder](http:\u002F\u002Fweblog.rubyonrails.org\u002F2009\u002F8\u002F31\u002Fthree-reasons-love-responder\u002F)\n* [My five favorite things about Rails 3](https:\u002F\u002Fweb.archive.org\u002Fweb\u002F20201109041436\u002Fhttps:\u002F\u002Fblog.engineyard.com\u002Fmy-five-favorite-things-about-rails-3)\n\n## Supported Ruby \u002F Rails versions\n\nWe intend to maintain support for all Ruby \u002F Rails versions that haven't reached end-of-life.\n\nFor more information about specific versions please check [Ruby](https:\u002F\u002Fwww.ruby-lang.org\u002Fen\u002Fdownloads\u002Fbranches\u002F)\nand [Rails](https:\u002F\u002Fguides.rubyonrails.org\u002Fmaintenance_policy.html) maintenance policies, and our test matrix.\n\n## Bugs and Feedback\n\nIf you discover any bugs or want to drop a line, feel free to create an issue on GitHub.\n\n## License\n\nMIT License.\nCopyright 2020-CURRENT Rafael França, Carlos Antonio da Silva.\nCopyright 2009-2019 Plataformatec.\n","Responders 是一组模块，旨在简化 Rails 应用程序中的控制器响应处理。其核心功能包括 FlashResponder、HttpCacheResponder、CollectionResponder 和 LocationResponder 等，能够自动设置闪现消息、添加 HTTP 缓存头、重定向到集合以及使用可调用对象作为重定向位置。通过这些功能，开发者可以大幅减少重复代码，提高开发效率。适用于需要优化用户体验和增强应用性能的场景，特别是在处理表单提交、API 请求及资源管理时。",2,"2026-06-11 03:15:52","top_language"]