繁体   English   中英

rails_admin编辑belongs_to排序

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM