Is there a way to access the data from Active Admin? Im creating a mobile app that will connect to an active admin website. I need to retrieve data from the website.
1 Answer
We are using "active_model_serializers" gem for this. To make it work just:
- Add active_model_serializers to your
Gemfile
- Add the following to
config/initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
before_action { self.namespace_for_serializer = ::Admin }
end
- Put your serializers into
app/serializers/admin/
folder
# app/serializers/admin/user_serializer.rb
module Admin
class UserSerializer < ::ActiveModel::Serializer
attributes :id, :username
end
end
And that's it. Now you should be able to make requests with JSON format to your ActiveAdmin endpoints.