【问题标题】:rails_admin edit belongs_to orderingrails_admin 编辑 belongs_to 排序
【发布时间】:2013-08-12 20:29:57
【问题描述】:

我正在尝试覆盖新/编辑表单的 belongs_to 下拉菜单的默认顺序。我想订购belongs_to关系来命名而不是默认的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

在提取语句时似乎忽略了重新排序。

【问题讨论】:

    标签: ruby-on-rails rails-admin


    【解决方案1】:

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

    调试此问题的一个好方法是打开一个 Rails 控制台并查看您的重新排序是否真的以这种方式工作。

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

    我猜这可能无法按预期工作,您需要调整重新排序。

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

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

    这可能会为您提供有关问题所在的更多信息。

    【讨论】:

    • 感谢您的评论。你说得对,我的意思是输入单数名称。一切都在控制台中检出——它以正确的顺序返回值。
    • @mscccc 你找到解决方案了吗?
    猜你喜欢
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多