ActiveAdmin 和就地编辑

发布于 2024-12-08 11:31:59 字数 145 浏览 1 评论 0原文

我有一个系统,我使用 ActiveAdmin 来自动化后端,我想知道是否有人尝试对 ActiveAdmin 的表进行就地编辑。

我看到一些有用的场景:键值表(如状态、类别等)和主从视图(订单和订单项)...

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2024-12-15 11:31:59

我们使用了 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 操作,并且 BestInPlace 也正在使用 RESTful PUT 进行更新,所以一切都应该自动工作:)

你也可以使用类似的东西,但我还没有测试过。

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

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
夜雨飘雪 2024-12-15 11:31:59

实际上,用于 Active Admin 视图的 Best In Place 猴子补丁非常简单:

# app/admin/active_admin/views.rb
module ActiveAdmin::ViewHelpers
  extend BestInPlace::BestInPlaceHelpers
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文