{"id":26576701,"url":"https://github.com/piotr-galas/rails_form_object","last_synced_at":"2026-05-06T11:31:33.178Z","repository":{"id":56890552,"uuid":"105434569","full_name":"piotr-galas/rails_form_object","owner":"piotr-galas","description":"It allows to create very simple form object behave like active model","archived":false,"fork":false,"pushed_at":"2017-10-14T21:01:31.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T23:06:10.817Z","etag":null,"topics":["form-objects","rails","validation"],"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/piotr-galas.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}},"created_at":"2017-10-01T10:28:35.000Z","updated_at":"2017-10-01T12:10:19.000Z","dependencies_parsed_at":"2022-08-21T00:20:34.012Z","dependency_job_id":null,"html_url":"https://github.com/piotr-galas/rails_form_object","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/piotr-galas/rails_form_object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-galas%2Frails_form_object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-galas%2Frails_form_object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-galas%2Frails_form_object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-galas%2Frails_form_object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotr-galas","download_url":"https://codeload.github.com/piotr-galas/rails_form_object/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-galas%2Frails_form_object/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261967137,"owners_count":23237663,"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":["form-objects","rails","validation"],"created_at":"2025-03-23T03:26:38.093Z","updated_at":"2026-05-06T11:31:28.134Z","avatar_url":"https://github.com/piotr-galas.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RailsFormObject\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rails_form_object'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rails_form_object\n    \n## Intention\n    \nIt allow you to move validations away from models. It get `hash` of params, or `strong parameters` as initializer instead of `model instance` and then run `active_model` validations on it\n\nGem allow you to:\n  - validates `hashes` or `strong_parameters`\n  - use standard validations from `active_model`\n  \nGem do not allow you to:\n  - validates models directly, because of simplicity\n  - save model, because of single responsibility principle\n\n## Usage\n\nTo define form_object you need to specify list of attributes to validation, and then define standard `active_model` validations\n\n```ruby\n class UserEditFriendData \u003c RailsFormObject::Base\n   attributes :frist_name, :last_name\n   validates :first_name, :last_name, presence: true\n   validate :custom_validation\n     \n   def custom_validation\n     # custom validator here\n   end\n end\n```\n\nExample usage of `UserEditOwnData` in controller\n \n```ruby\n  class FriendsController \u003c ActionController::Base\n    def new \n      @friend_form = UserEditFriendData.new\n    end\n    \n    def edit\n       friend = Friend.find(params[:id])\n       @friend_form = UserEditFriendData.new(friend.attributes)\n    end\n    \n    def create\n      @friend_form = UserEditFriendData.new(friend_params)\n      if @friend_form.valid?\n         friend = Friend.new(friend_params)\n         friend.save(validation: false)\n         redirect_to friend\n      else\n         render :new\n      end\n    end\n    \n    def update\n      @friend_form = UserEditFriendData.new(friend_params)\n      if @friend_form.valid?\n         friend = Friend.find(params[:id])\n         friend.assign_attributes(friend_params)\n         friend.save(validation: false)\n         redirect_to friend\n      else\n         render :edit\n      end\n    end\n    \n    def friend_params\n      params.require(:user_edit_friend_data).permit(:first_name, :last_name)\n    end\n  end\n``` \n\n## TODO\n PR are welcome\n \n - Add support for nested attributes and nested form\n - Add optional uniqueness validator\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. Then run `rubocop` 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/piotr-galas/rails_form_object. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotr-galas%2Frails_form_object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotr-galas%2Frails_form_object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotr-galas%2Frails_form_object/lists"}