How to set up Rails API app to use ActiveAdmin?

Gustavo Gonzalez
Jun 12, 2018 · 3 min read

As I said in a previous post, our default development stack uses Ruby on Rails as back-end and ReactJS/React Native as front-end. In almost every project, besides developing the front-end interface for the final user, we need to implement some administration UI for the admins so he could manage/review app data.

When we use Ruby on Rails as back-end server, we usually set the app as API only causing that some functionalities are disabled by default like sessions, cookies, rendering views and so on.

rails new my_api_app --api # Run this command on your terminal to create a rails app in API mode.

Rails ecosystem includes some gems that allows to create admin stuff in an easy way, so most of the time it is easier to use one of these gems to allow admins to manage the data. One of the most used gems int this regard is ActiveAdmin.

Since we had set up our app in API mode, some rails middleware is disabled, the following steps will help us to set up our app so we can use ActiveAdmin without issues:

1. Enable sprockets to allow ActiveAdmin to use assets

To achieve this we need to uncomment the following line in config/application.rb

require "sprockets/railtie"

2. Enable cookies if we are going to use Devise (or any other auth gem)

On the same file config/application.rb we should include the following lines:

config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore

3. Enable MethodOverride

If we want to use all HTTP verbs as DELETE and PATCH we need to add the following line in config/application.rb

config.middleware.use Rack::MethodOverride

This is necessary because these verbs are simulated in Ruby on Rails using a POST request with a param called _method in the request's body.

4. Enable flash messages (notice/alert)

To be able to render flash messages in the pages, we should include the following line also inconfig/application.rb

config.middleware.use ActionDispatch::Flash

5. Modify ApplicationController

ActiveAdmin uses/depends of ApplicationController to works as expected since their controllers inherit from this class. In API mode apps, ApplicationController inherits from ActionController::API and it breaks ActiveAdmin. To fix it we should change application_controller.rb to makes ApplicationController inherits from ActionController::Base

To be able to continue using API stuff, an advise is to create a new controller for example ApiController that inherits from ActionController::API

Finally, our config/application.rb should look something like the following


Wrapping up

Although it seems daunting at first, using some simple configuration steps, we could setup a Rails API only app to be able to use ActiveAdmin for the admin management, keeping the advantages of using Rails and React for the rest of the project.

If you like this story clap as many times as you want, and to see similar stories about technology, check our publications and leave us a comment if you have any question.

If you need a team that can help you to implement your ideas in React JS or React Native, feel free to ping us using our website and filling the contact form.

Spanish version

Twitter: @Aguardientico
Blog in spanish:


IT consulting. #Agile and #Lean remote software development team specialized in #web, #mobile, #reactjs and #rubyonrails from #Ecuador.

Gustavo Gonzalez

Written by

25+ years in software development. Loves to learn new technologies and share his knowledge with others.


IT consulting. #Agile and #Lean remote software development team specialized in #web, #mobile, #reactjs and #rubyonrails from #Ecuador.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade