{"id":21228204,"url":"https://github.com/hexlet/active_form_model","last_synced_at":"2025-09-01T10:04:54.585Z","repository":{"id":42008930,"uuid":"274003862","full_name":"Hexlet/active_form_model","owner":"Hexlet","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-26T18:36:04.000Z","size":51,"stargazers_count":55,"open_issues_count":0,"forks_count":16,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-08-09T19:52:42.614Z","etag":null,"topics":["hacktoberfest"],"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/Hexlet.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-06-22T00:11:42.000Z","updated_at":"2025-07-17T01:48:48.000Z","dependencies_parsed_at":"2025-02-24T04:13:55.026Z","dependency_job_id":"fff0bac9-6a07-41ad-a706-ebbf15bffdad","html_url":"https://github.com/Hexlet/active_form_model","commit_stats":null,"previous_names":["hexlet/form-model"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/Hexlet/active_form_model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexlet%2Factive_form_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexlet%2Factive_form_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexlet%2Factive_form_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexlet%2Factive_form_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hexlet","download_url":"https://codeload.github.com/Hexlet/active_form_model/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexlet%2Factive_form_model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273105953,"owners_count":25046950,"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-09-01T02:00:09.058Z","response_time":120,"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":["hacktoberfest"],"created_at":"2024-11-20T23:15:01.979Z","updated_at":"2025-09-01T10:04:54.557Z","avatar_url":"https://github.com/Hexlet.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveFormModel\n\n[![github action status](https://github.com/Hexlet/active_form_model/workflows/main/badge.svg)](https://actions-badge.atrox.dev/hexlet/hexlet-cv/goto)\n\nPainless forms for ActiveRecord. Based on Inheritance. Included:\n\n* Strong parameters\n* Validation (based on the model validation)\n* Data normalization\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_form_model'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install active_form_model\n\n## Usage\n\n1. Create directory *app/forms*\n1. Add Form class for a model\n1. Add permitted params inside the class\n1. Use it as a normal model (without strong_params)\n\n## Generator\n\nUse the supplied generator to generate forms:\n\n    $ rails g active_form_model:form sign_up --model=user\n\nor with namespace model\n\n    $ rails g active_form_model:form admin_post --model=blog/post\n\n### Example\n\n```ruby\n# app/forms/user_sign_up_form.rb\nclass UserSignUpForm \u003c User\n  include ActiveFormModel\n\n  # list all the permitted params\n  permit :first_name, :email, :password\n\n  # add validation if necessary\n  # they will be merged with base class' validation\n  validates :password, presence: true\n\n  # optional data normalization\n  def email=(email)\n    if email.present?\n      write_attribute(:email, email.downcase)\n    else\n      super\n    end\n  end\nend\n```\n\nIn some cases it is necessary to use ActiveRecord object directly without form. For such cases conveniently to use method `becomes()` (built-in ActiveRecord):\n\n```ruby\nuser = User.find(params[:id])\nform = user.becomes(UserSignUpForm)\n```\n\nIf you want to build virtual form that is not tied to any class:\n\n```ruby\n# frozen_string_literal: true\n\nclass SignInForm\n  include ActiveFormModel::Virtual\n\n  fields :email, :password\n\n  validates :email, presence: true\n  validates :password, presence: true\n  validate :user_exists, :user_can_sign_in\n\n  def user_can_sign_in\n    errors.add(:password, :cannot_sign_in) if password.present? \u0026\u0026 !user\u0026.valid_password?(password)\n  end\n\n  def user_exists\n    errors.add(:email, :user_does_not_exist_html) if email.present? \u0026\u0026 !user\n  end\n\n  def user\n    @user ||= User.find_by(email: email)\n  end\n\n  def email=(value)\n    @email = value.downcase\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\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/[USERNAME]/active_form_model. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/active_form_model/blob/master/CODE_OF_CONDUCT.md).\n\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 ActiveFormModel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_form_model/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexlet%2Factive_form_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexlet%2Factive_form_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexlet%2Factive_form_model/lists"}