[英]Using rails_admin to display dropdown list on belongs_to association
[英]rails_admin edit belongs_to ordering
我正在嘗試覆蓋新/編輯表單的belongs_to下拉列表的默認順序。 我想將belongs_to關系命名為name而不是默認的id desc。
基於wiki( https://github.com/sferik/rails_admin/wiki/Associations-scoping )我有這個:
field :theme do
associated_collection_cache_all false
associated_collection_scope do
Proc.new { |scope|
scope = scope.reorder("themes.name ASC")
}
end
end
end
在拾取語句的地方,似乎忽略了重新排序。
您確定要排序的列是“名稱”而不是“名稱”嗎?
調試這個的一個好方法是打開一個rails控制台,看看你的重新排序實際上是否正常工作。
Theme.all.reorder("themes.names ASC")
我猜這可能不會按預期工作,你需要調整重新排序。
如果你想看到它正在創建的SQL,你可以這樣做。
Theme.all.reorder("themes.names ASC").to_sql
這可能會為您提供有關出錯的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.