【问题标题】:Sort nested objects in Rails 2.3在 Rails 2.3 中对嵌套对象进行排序
【发布时间】:2010-01-05 05:15:33
【问题描述】:

我有一个包含嵌套对象的表单,如下所述:

http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

它工作正常,但我需要按其“名称”属性对表单中的嵌套对象进行排序,以便它们按字母顺序列出。

有什么想法吗?

【问题讨论】:

  • 源不再可用

标签: ruby-on-rails


【解决方案1】:

为关联设置默认排序,例如:

has_many :children, :order => "name"

【讨论】:

    【解决方案2】:

    我最终只是在嵌套模型的默认范围内设置了排序顺序:

    default_scope :order => 'name'
    

    【讨论】:

      猜你喜欢
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 2018-07-02
      • 2015-11-10
      • 2016-07-09
      相关资源
      最近更新 更多