ActiveAdmin Active Resource Gem Version

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

WARNING: this component is a Beta version, some Active Admin functionalities don't work as expected:

  • Filters: partially supported (see example)
  • Edit: fields must be configured explicitly
  • Comments: not supported

Install

  • Add to your Gemfile: gem 'activeadmin_active_resource'
  • Execute bundle
  • Disable comments in active_admin config initializer

Example

  • Post model:
class Post < ActiveResource::Base
  self.site = 'http://localhost:3000'  # API url: another Rails project, a REST API, etc.

  self.schema = {  # Fields must be declared explicitly
    id: :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.register Post do
  filter :title_cont  # Ransack postfixes required (_eq, _cont, etc.)

  controller do
    def permitted_params
      params.permit!  # Permit all just for testing
    end
  end

  form do |f|
    f.inputs do
      f.input :id, as: :hidden unless f.object.new_record?  # Required
      f.input :title
      # ... other fields
    end
    f.actions
  end
end
  • Ransack options here

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.

Take a look at other ActiveAdmin components that I made if you are curious.

Contributors

License

MIT