ActiveAdmin and in-place edit

a 夏天 提交于 2019-11-30 02:28:21
Severin Ulrich

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

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!