Repository is archived
No commit activity in last 3 years
No release in over 3 years
Provides ability to use form object in your ActiveAdmin application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.4.3, < 3.0
>= 0.2.0
>= 4.0.0, < 6.0
<= 2.3.0.rc1
<= 0.2.0.rc2
 Project Readme

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.