ActiveAdmin Form Field For Strongbox Encrypted Attribute
If you are using ActiveAdmin or formtastic (which ActiveAdmin uses under the hood) and are having trouble rendering a form with an encrypted attribute like with Strongbox 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
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.