{"id":20061625,"url":"https://github.com/tylerrick/button_to_form","last_synced_at":"2025-10-11T13:09:54.985Z","repository":{"id":62554765,"uuid":"227480451","full_name":"TylerRick/button_to_form","owner":"TylerRick","description":"A button_to helper that can be used inside a form tag (unlike Rails's own button_to)","archived":false,"fork":false,"pushed_at":"2019-12-12T22:22:30.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-11T13:09:54.566Z","etag":null,"topics":["button","buttons","form","form-helper","form-helpers","forms","rails","view-helper","view-helpers"],"latest_commit_sha":null,"homepage":null,"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/TylerRick.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","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":"2019-12-11T23:34:46.000Z","updated_at":"2019-12-12T22:18:55.000Z","dependencies_parsed_at":"2022-11-03T05:15:29.105Z","dependency_job_id":null,"html_url":"https://github.com/TylerRick/button_to_form","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/TylerRick/button_to_form","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fbutton_to_form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fbutton_to_form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fbutton_to_form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fbutton_to_form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerRick","download_url":"https://codeload.github.com/TylerRick/button_to_form/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fbutton_to_form/sbom","scorecard":{"id":144790,"data":{"date":"2025-08-11","repo":{"name":"github.com/TylerRick/button_to_form","commit":"5c49831789cd209b44c1a0d1642bf5befe657a8c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/2 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: License:0","Info: FSF or OSI recognized license: MIT License: License:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T09:10:35.688Z","repository_id":62554765,"created_at":"2025-08-16T09:10:35.688Z","updated_at":"2025-08-16T09:10:35.688Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007311,"owners_count":26084280,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["button","buttons","form","form-helper","form-helpers","forms","rails","view-helper","view-helpers"],"created_at":"2024-11-13T13:20:59.878Z","updated_at":"2025-10-11T13:09:54.968Z","avatar_url":"https://github.com/TylerRick.png","language":"Ruby","readme":"# `button_to_form`\n\n[![Gem Version](https://badge.fury.io/rb/button_to_form.svg)](https://badge.fury.io/rb/button_to_form)\n[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rdoc.info/github/TylerRick/button_to_form/)\n\n## Motivation\n\nThe [button_to](https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to)\nprovided by rails _doesn't work_ when used inside of a `\u003cform\u003e` tag, because it adds a new `\u003cform\u003e`\n(at your current nesting level) and HTML doesn't allow a `form` to be nested within another `form`.\n\n## How does it work?\n\nThe HTML spec _does_, however, allow a button/input/etc. to be\nassociated with a different form than the one it is nested within.\n\nThe [HTML spec says](https://html.spec.whatwg.org/#association-of-controls-and-forms):\n\n\u003e A form-associated element is, by default, associated with its nearest ancestor form element\n\u003e (as described below), but, if it is listed, may have a form attribute specified to override\n\u003e this.\n\nThis helper takes advantage of that, rendering a separate, empty `\u003cform\u003e` in the footer, and then\nassociating this `button` with it, so that it submits to *that* `form`'s action _rather_ than to the\naction of the `form` it is a descendant of.\n\nSo — assuming you have added `\u003c%= content_for(:footer) %\u003e` somewhere in your layout — this source:\n\n```ruby\n= form_tag '/main_form' do\n  = hidden_field_tag :main_form_param_1, 'main_form'\n  = text_field_tag   :main_form_param_2, ''\n\n  = button_to_form 'Make happy', '/make_happy' do\n    = hidden_field_tag :how_happy, 'ecstatic!'\n```\n\nwill get rendered to HTML that looks something like this:\n```html\n  \u003cform action=\"/main_form\" accept-charset=\"UTF-8\" method=\"post\"\u003e\n    \u003cinput type=\"hidden\" name=\"main_form_param_1\" id=\"main_form_param_1\" value=\"main_form\"\u003e\n    \u003cinput type=\"text\" name=\"main_form_param_2\" id=\"main_form_param_2\" value=\"\"\u003e\n    \u003cbutton name=\"button\" type=\"submit\" form=\"form-1e7dc01b-46d0-4a44-908e-77fbe2a7ec98\"\u003eMake happy\u003c/button\u003e\n  \u003c/form\u003e\n  …\n  \u003cdiv id=\"footer\"\u003e\n    \u003cform id=\"form-1e7dc01b-46d0-4a44-908e-77fbe2a7ec98\" action=\"/make_happy\" accept-charset=\"UTF-8\" method=\"post\"\u003e\n      \u003cinput type=\"hidden\" name=\"how_happy\" id=\"how_happy\" value=\"ecstatic!\"\u003e\n    \u003c/form\u003e\n  \u003c/div\u003e\n```\n\nAs you can see, there are 2 `\u003cform\u003e` tags that get rendered, but neither of them is nested within\nthe other, so it is allowed — and works well! Now you can include `button_to` calls inside of\nother forms as much as your heart desires.\n\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n```ruby\ngem 'button_to_form'\n```\n\nFor this helper to work, you *must* also include this somewhere in your layout:\n```ruby\n  \u003c%= content_for(:footer) %\u003e\n```\n\nIf you want these forms to be added to a different `content_for` key, say `:forms`, you can\nconfigure it like so:\n```ruby\nButtonToFormHelper.content_for_name = :forms\n```\n\n## Usage\n\nBy default, it will generate a unique id for the form. In its simplest form, it can be used as a\ndrop-in replacement for Rails's `button_to`. Example:\n\n```ruby\n  = button_to_form 'Make happy', [:make_happy, user]\n```\n(These examples use HAML, but you could just as easily use ERB.)\n\nUnless you have a use case where the default generated id doesn't work, it is recommended to use\nthat approach, as it ensures that each `button_to_form` call has its own corresponding unique\n`\u003cform\u003e`.\n\nIf, however, you need to reference this form in other places, you can specify a well-known id as the\nform's id. You can also pass other `form_options`, such as `method`.\n\n```ruby\n  = button_to_form 'Delete', thing,\n    {data: {confirm: 'Are you sure?'}},\n    {method: 'delete', id: 'delete_thing_form'}\n  = hidden_field_tag :some_id, some_id, {form: 'delete_thing_form'}\n```\n\nYou may pass along additional data to the endpoint via `hidden_field_tag`s by passing them inside a\nblock. You don't need to specify the `form` in this case because, as descendants, they are already\nassociated with this new form.\n\n```ruby\n  = button_to_form 'Delete', thing,\n    {data: {confirm: 'Are you sure?'}},\n    {method: 'delete'} do\n    = hidden_field_tag :some_id, some_id\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo start up a development web server with the same internal Rails app that is used for tests, run `rackup`.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/TylerRick/button_to_form.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Fbutton_to_form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerrick%2Fbutton_to_form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Fbutton_to_form/lists"}