我正在使用全球化和 i18n。我有以下型号:
class Result < ActiveRecord::Base
belongs_to :test
...
scope :sort_with_teaser, lambda { |direction|
joins(test: :test_translations).
where(test_translations: {locale: 'fr'}).
order("test_translations.teaser #{ direction }")
}
end
class Test < ActiveRecord::Base
translates :teaser
...
end
因此,使用 Globalize 和 I18n,我还有一个 test_translations 表。
我想在我的 Result 模型中实现一个范围 sort_with_teaser 以使用他们的 result.test.teaser 对结果进行排序。但我这段代码不起作用。
欢迎任何帮助。