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
所有藝術家被要求這樣做輸入:
我能做些什麼?
按照以下說明:https://github.com/josevalim/inherited_resources#overwriting-defaults – apneadiving