ActiveAdmin and in-place edit
Asked Answered
A

2

7

I have this system where I use ActiveAdmin to automate the backend and I was wondering if anyone tried to use in-place editing with tables for ActiveAdmin.

I see some scenarios where that would be useful: key-value tables (like State, Category, etc.) and in master-detail views (Order and OrderItems)...

Have anyone attempted to implement it? Any good pointers?

Atal answered 7/10, 2011 at 15:52 Comment(0)
M
9

We've used best_in_place Editor but only on customized views, not on generic ones.

https://github.com/bernat/best_in_place

gem "best_in_place"
bundle
rails g best_in_place:setup

Add the best_in_place script to /app/assets/javascripts/active_admin.js:

//= require best_in_place

$(document).ready(function() {
  /* Activating Best In Place */  
  jQuery(".best_in_place").best_in_place() });

in your custom view partial you can have something like

.panel
  %h3 Your Resource Table
  .panel_contents
    .attributes_table
      %table
        %tbody
          %tr
            %th Name
            %td= best_in_place resource, :name, :type => :input, :path => [:admin, resource]
            ...
            ...

As ActiveAdmin has already setup your RESTful Actions and BestInPlace is using RESTful PUT to Update too, everything should work automatically :)

You may can also use something like this, but I've not tested this yet.

index do
  column(:name) { |i| best_in_place i, :name, :type => :input, :path => [:admin, i] } 
end
Minerva answered 10/11, 2011 at 16:5 Comment(2)
I have managed to use that very same plugin in the generic ones, with minor changes. Might as well do a blog post when I stop being lazy about it :) Thank you!Atal
This is awesome. @Atal I'm interested in seeing how you got it to work with the generic ones, did you have to monkey-patch ActiveAdmin?Inculcate
O
5

Actually Best In Place monkey patch for Active Admin views is very easy:

# app/admin/active_admin/views.rb
module ActiveAdmin::ViewHelpers
  extend BestInPlace::BestInPlaceHelpers
end
Odle answered 11/7, 2012 at 23:17 Comment(1)
still works as of 3.1.0, but you want BestInPlace::HelperExecutor

© 2022 - 2024 — McMap. All rights reserved.