rails_admin编辑belongs_to排序

时间:2013-08-12 20:29:58

标签: ruby-on-rails rails-admin

我正在尝试覆盖新/编辑表单的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

在拾取语句的地方,似乎忽略了重新排序。

1 个答案:

答案 0 :(得分:0)

您确定要排序的列是“名称”而不是“名称”吗?

调试此方法的一个好方法是打开一个rails控制台,看看你的重新排序实际上是否正常工作。

Theme.all.reorder("themes.names ASC")

我猜这可能不会按预期工作,你需要调整重新排序。

如果你想看到它正在创建的SQL,你可以这样做。

Theme.all.reorder("themes.names ASC").to_sql

这可能会为您提供有关最新错误的更多信息。

相关问题