0.0
No commit activity in last 3 years
No release in over 3 years
Form objects for ruby on rails applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

FormObject

Build Status Code Climate Dependency Status Coveralls

TODO: Write a gem description

Installation

Add this line to your application's Gemfile:

gem 'form_object'

And then execute:

$ bundle

Or install it yourself as:

$ gem install form_object

Usage

We have a model

class User < ActiveRecord::Base
end

# attributes => {email: "test@example.com", name: "name"}

Define forms:

# For base auth
class BaseAuthForm < FormObject::Base
  map_model User, as: :base_auth
  attribute :email, String # => map form attribute to model attribute

  validates :email, presence: true # => validate email in form ONLY!
end

# For any other auth
class TwitterAuthForm < FormObject::Base
  map_model User      # name => twitter_auth (name will be generated 
                      # automatically from class name)
                      # There is nothing to validate
end

In any place:

  @user = User.find(params[:id])
  @form = @user.form( :base_auth ) # This retrive BaseAuthForm instance
                                  # with attributes from model
  @form.assign_attributes(params[:user]) # assign attributes from hash

  if @form.valid?
    @form.persist_model           # TODO: maybe other method name?
  end

Can I help you?

Discuss the existing features and offer new features you can here.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request