Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

bolshakov/activeadmin-reform

Repository files navigation

Build Status Test Coverage Code Climate Gem Version

ActiveAdmin Reform

This gem adds integration between ActiveAdmin and Reform. So you may use form objects for your forms.

The purpose of this gem is to provide ability to define custom ActiveAdmin-specific validations for your models. Using form objects allows you to define such validations without cluttering model's code and simplifies building test objects.

Installation

Add this line to your application's Gemfile:

gem 'activeadmin-reform'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activeadmin-reform

Usage

Define your form object and include our mixin (ActiveAdmin::Reform::ActiveRecord) into it:

require 'reform'

class AuthorForm < Reform::Form
  include ActiveAdmin::Reform::ActiveRecord

  model :author

  property :last_name, validates: { presence: true }
  property :name
end

Specify form class for ActiveAdmin resource:

ActiveAdmin.resource Author do
  form_class AuthorForm
  
  form do |f|
    f.semantic_errors(*f.object.errors.keys)

    f.inputs do
      f.input :name
      f.input :last_name
    end

    f.actions
  end
end

Now ActiveAdmin will use Reform form object to validate form. Note, you must explicitly define form for resource.

By default ActiveAdmin will not use Reform, but if you want to reopen resource and disable form object usage, pass false instead of class:

ActiveAdmin.resource Author do
  form_class false
end

Contributing

The contributing guide is a good place to start.

License

The gem is available as open source under the terms of the MIT License.