Using Ruby on Rails Active Storage image uploads for Active Admin backed resources

Māris Cīlītis
1 min readFeb 22, 2018

--

Active Admin is a Ruby on Rails framework for creating elegant backends for website administration. You can create awesome admin dashboards in a matter of minutes.

When testing new Rails 5.2 Active Storage engine I stumbled up on a fact that Active Admin does not work as I thought it should. When processing image uploads using carrierwave, Active Admin automatically detected uploader and rendered the file upload field.

Imagine a code like this:

To get the image file uploading work with Active Admin you need to specify your own form partial. Luckily for us, Active Admin provides a clean way of doing this. You just specify a partial name in a Active Admin resource configuration and whitelist the image param. You can see the example code below.

Then just create a template file with a file field in it.

Refresh the page and you should be able to add a file. To see the uploaded file, just use the helpers method provided by Ruby on Rails in your Active Admin resource configuration.

Refresh the page, and your image is visible!

Happy coding!

--

--