加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ActiveAdmin和就地编辑

发布时间:2020-12-17 04:21:14 所属栏目:百科 来源:网络整理
导读:我有这个系统,我使用ActiveAdmin自动化后端,我想知道是否有人尝试使用ActiveAdmin的表进行就地编辑. 我看到一些有用的场景:键值表(如State,Category等)和master-detail视图(Order和OrderItems)…… 有没有人试图实现它?有什么好的指针吗? 解决方法 我们使
我有这个系统,我使用ActiveAdmin自动化后端,我想知道是否有人尝试使用ActiveAdmin的表进行就地编辑.

我看到一些有用的场景:键值表(如State,Category等)和master-detail视图(Order和OrderItems)……

有没有人试图实现它?有什么好的指针吗?

解决方法

我们使用了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,i] } 
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读