Skip to content

Repository files navigation

Active Admin + Active Resource

gem versiongem downloadslintersspecsspecs2

An Active Admin plugin to use a REST API data source in place of a local database using Active Resource.

NOTICE: currently some Active Admin features don't work as expected:

  • Filters are partially supported (see example)
  • Some form fields must be configured explicitly (like the associations)
  • Comments are not supported

Please ⭐ if you like it.

Install

  • Add to your project's Gemfile (with Active Admin installed): gem 'activeadmin_active_resource'
  • Execute bundle
  • Disable comments in Active Admin config initializer (config.comments = false)

Examples

Please take a look at the examples folder:

  • a Rails6 application with Active Admin and this component, see here;
  • a Rails6 API application used as data source, see here;
  • a Roda API application used as data source, see here.

For more examples check the specs.

Basic instructions:

  • Post model:
classPost < ActiveResource::Baseself.site='http://localhost:3000'# API url: another Rails project, a REST API, etc.self.schema={# Fields must be declared explicitlyid: :integer,title: :string,description: :text,author_id: :integer,category: :string,dt: :datetime,position: :float,published: :boolean,created_at: :datetime,updated_at: :datetime,}end
  • Post admin config:
ActiveAdmin.registerPostdofilter:title_cont# Ransack postfixes required (_eq, _cont, etc.)controllerdodefpermitted_paramsparams.permit!# Permit all just for testingendendformdo |f|
f.inputsdof.input:id,as: :hiddenunlessf.object.new_record?# Requiredf.input:title# ... other fieldsendf.actionsendend
  • Ransack options here
  • Rails API index example with Ransack and Kaminari:
after_action:set_pagination,only: [:index]defindexper_page=params[:per_page].to_iper_page=15ifper_page < 1@posts=Post.ransack(params[:q]).result.order(params[:order]).page(params[:page].to_i).per(per_page)enddefset_paginationheaders['Pagination-Limit']=@posts.limit_value.to_sheaders['Pagination-Offset']=@posts.offset_value.to_sheaders['Pagination-TotalCount']=@posts.total_count.to_send

Notes

If you create a new rails project don't use --skip-active-record.

Do you like it? Star it!

If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other Active Admin components.

Or consider offering me a coffee, it's a small thing but it is greatly appreciated: about me.

Contributors

License

The gem is available as open-source under the terms of the MIT.

About

Active Admin + Active Resource: to use a REST API in place of a local database as data source

Topics

Resources

Stars

30 stars

Watchers

5 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages