Ruby on rails I18n带_平移和where条件
我正在尝试对具有翻译表的鉴定书运行一个查询 以下查询工作起来就像一个符咒:Ruby on rails I18n带_平移和where条件,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.2,rails-i18n,globalize3,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.2,Rails I18n,Globalize3,我正在尝试对具有翻译表的鉴定书运行一个查询 以下查询工作起来就像一个符咒: Testimonial.with_translations(I18n.locale).where(:id => params[:id]).first 当我将查询更改为: Testimonial.with_translations(I18n.locale).where(:alias => "test").first 它不返回任何值? where类为true时存在记录: => [#<Testimo
Testimonial.with_translations(I18n.locale).where(:id => params[:id]).first
当我将查询更改为:
Testimonial.with_translations(I18n.locale).where(:alias => "test").first
它不返回任何值?
where类为true时存在记录:
=> [#<Testimonial id: 1, title: "Test", person: "", image_uid: nil, content: "<p>zfzefzfLorem ipsum dolor sit amet, consectetur a...", interest_group: "", created_at: "2015-01-15 11:48:11", updated_at: "2015-01-15 11:48:11", job: "", overview: true, content_short: "<p>Lorem ipsum dolor sit amet, consectetur adipisci...", hidden: false, hide_image: false, alias: "test">]
这些是我的规格:
- ruby 1.9.3p550(2014-10-27修订版48165)[x86_64-darwin13.4.0]
- 轨道3.2.19
有了这些知识,我需要做两个查询 您可以尝试将
添加到\u sql
中,以检查sql查询生成的内容
Testimonial.with_translations(I18n.locale).where(:alias => "test").to_sql
您是否尝试过使用带有翻译属性的
“从“推荐书”中选择“推荐书”*“推荐书翻译”中的“语言环境”=“nl”和“推荐书”中的“别名”=“测试”。这似乎是在推荐书上而不是推荐书翻译中的“位置”上做的。您是否在使用globalize gem?稍微检查一下代码,我认为您可以使用带有翻译属性的方法
Testimonial.with_translations(I18n.locale).where(:alias => "test").to_sql