2011-10-07 49 views
7

我有這個系統,我使用ActiveAdmin來自動化後端,我想知道是否有人試圖使用ActiveAdmin的表就地編輯。ActiveAdmin和in-place編輯

我看到的一些情形,這將是有益的:鍵值表(如國家,類別等),並在主詳細的意見(訂單和的OrderItems)...

有任何人企圖實施它?任何好的指針?

回答

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正在使用RES Tful PUT來更新,一切都應該自動工作:)

你也可以使用類似的東西,但我還沒有測試過。

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

我已成功地使用同樣的插件在通用的,具有輕微的變化。當我停止懶惰時,不妨做一篇博客文章:)謝謝! – kolrie

+0

這太棒了。 @kolrie我感興趣的是如何讓它與通用的一起工作,你是否需要對ActiveAdmin進行猴子補丁? – David

+0

太棒了。也爲我工作。 – RailsTweeter

5

其實最好的地方猴子補丁主動管理的意見很簡單:

# app/admin/active_admin/views.rb 
module ActiveAdmin::ViewHelpers 
    extend BestInPlace::BestInPlaceHelpers 
end 
+1

仍然適用於3.1.0,但您希望'BestInPlace :: Helper' – sbeam