ActiveAdmin Form Field For Strongbox Encrypted Attribute

If you are using [ActiveAdmin][1] or [formtastic][2] (which ActiveAdmin uses under the hood) and are having trouble rendering a form with an encrypted attribute like with [Strongbox][3] the solution is very, very simple. Perhaps though it is not so obvious.

What you might be seeing is something like this…

Unable to find input class for binary

With the source of the error being

insert_tag renderer_for(:new)

Fix It! #

Lets look at this contrived example and assume that the ssn attribute is encrypted by Strongbox on our User model. The ssn column in my experience then should be a binary type in your db/schema.rb. That translates to bytea in Postgresql, and blob in MySQL and Sqlite3.

  form do |f| 
    f.inputs "User" do
      f.input :email
      f.input :password
      f.input :ssn
    end 
    f.actions
  end

All we have to do in order to get out of this hole is to tell formtastic we want to interact with this binary attribute as if it were a regular string attribute.

  form do |f| 
    f.inputs "User" do
      f.input :email
      f.input :password
      f.input :ssn, as: :string
    end 
    f.actions
  end

What is happening here is that formtastic is trying to do some intelligent inspection on the attribute’s type. As of version 2.3.0.rc2 formtastic does not make any assumptions about how you would want to interact with a binary attribute with a form, at least that is my suspicion. In the case of an encrypted attribute though, at least in the way Strongbox works, we do write to the attribute just as we would any other string column.

I hope this helps someone, but if it doesn’t it gave me something to write about and a break from code for a few minutes.

[1]: http://activeadmin.info/ “ActiveAdmin”
[2]: https://github.com/justinfrench/formtastic “formtastic on Github”
[3]: https://github.com/spikex/strongbox “Strongbox on Github”

 
26
Kudos
 
26
Kudos

Now read this

Benchmarking RandomX on Mac

I wanted to test my MBP CPU out on the incoming Monero algorithm RandomX but there are no builds for Mac and I wasn’t in the mood to try and compile from source on Mac. Docker to the rescue! Install Docker Desktop... Continue →