2014-01-28 69 views
0

關聯模型Rails應用程序中,我有兩個模式是這樣的:如何包括active_admin

class Painting < ActiveRecord::Base 
    belongs_to :artist 
end 

class Artist < ActiveRecord::Base 
    belongs_to :country 

    def display_name 
    text = to_s 
    if birth_year 
     death = death_year || "----" 
     text += " (#{birth_year}-#{death})" 
    end 
    text += ", #{country.name}" 
    end 

end 

class Country < ActiveRecord::Base 
    active_admin_translates :name 
end 

我使用主動管理這樣

ActiveAdmin.register Painting do 
end 

的問題比display_name方法需要撥打國家和翻譯表格。有很多藝術家,運行時間很長。我正在尋找一種方法來提高速度。

請求似乎是這樣的:

SELECT "artists".* FROM "artists" WHERE "artists"."accepted" = 't' ORDER BY name 
SELECT "countries".* FROM "countries" WHERE "countries"."id" = 50 ORDER BY name LIMIT 1 

所有藝術家被要求這樣做輸入: select image

我能做些什麼?

+0

按照以下說明:https://github.com/josevalim/inherited_resources#overwriting-defaults – apneadiving

回答

1

您是否嘗試過在控制器上設置scoped_collection?

我覺得這件事情是這樣的:在這裏

ActiveAdmin.register Painting do 
    controller do 
    def scoped_collection 
     Painting.joins({artist: {country: :translations}}) 
    end 
    end 
end 

更多信息可供選擇:http://www.activeadmin.info/docs/2-resource-customization.html

+0

我糾正了我題。調用請求來執行輸入。 – Dougui