我正在使用globalize和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对结果进行排序。但我这段代码不起作用。
欢迎任何帮助。
答案 0 :(得分:0)
好的,我刚修好了:
joins(test: :translations).where(test_translations: {locale: 'fr'}).order("test_translations.teaser #{ direction }")