ActiveAdmin和原地编辑

7

我有一个系统,使用ActiveAdmin自动化后端,我想知道是否有人尝试在ActiveAdmin中使用表格进行原地编辑。

我看到一些场景会用到它:键值表(例如State、Category等)和主从视图(Order和OrderItems)...

有没有人尝试过实现它?有什么好的指点?

2个回答

9
我们使用了best_in_place编辑器,但仅在自定义视图上使用,而不是通用视图。 https://github.com/bernat/best_in_place
gem "best_in_place"
bundle
rails g best_in_place:setup

将best_in_place脚本添加到/app/assets/javascripts/active_admin.js文件中:
//= require best_in_place

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

在你的自定义视图部分中,你可以有类似以下内容的代码:
.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]
            ...
            ...

由于ActiveAdmin已经设置了您的RESTful Actions,而BestInPlace也使用RESTful PUT进行更新,因此一切都应该自动运行 :)

您也可以尝试类似以下的操作,但我还没有测试过。

index do
  column(:name) { |i| best_in_place i, :name, :type => :input, :path => [:admin, i] } 
end

我已经成功地在通用插件中使用了同样的插件,并进行了一些小的更改。如果我不再懒惰,我也可以写一篇博客文章 :) 谢谢! - kolrie
这太棒了。@kolrie,我很想看看你是如何让它与通用的那些一起工作的,你是否需要对ActiveAdmin进行猴子补丁? - David

5
实际上,在Active Admin视图中使用Best In Place monkey patch非常容易:
# app/admin/active_admin/views.rb
module ActiveAdmin::ViewHelpers
  extend BestInPlace::BestInPlaceHelpers
end

1
截至3.1.0版本仍然有效,但你需要使用BestInPlace::Helper - sbeam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接