我有一张桌子mobility_string_translations,但我不知道如何到达它。
现在我有三张唱片。两张德文唱片和一张西班牙文唱片。我只想要那些德文的记录。
这是行不通的:
all_de_posts = Post.i18n.find_by(locale: :de)发布于 2018-09-26 19:16:51
首先,你可能有一个专栏。(比如说标题。)
在您的模型post.rb中,您将得到如下内容:
class Post < ApplicationRecord
extend Mobility
translates :title, type: :string, locale_accessors: [:en, :de]
end 要获得:de记录(或:en),类型非常重要。
在mobility_string_translations,schema.rb会看到一张桌子
create_table "mobility_string_translations", force: :cascade do |t|
t.string "locale", null: false
t.string "key", null: false
t.string "value"
t.integer "translatable_id", null: false
t.string "translatable_type", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["translatable_id", "translatable_type", "key"], name: "index_mobility_string_translations_on_translatable_attribute"
t.index ["translatable_id", "translatable_type", "locale", "key"], name: "index_mobility_string_translations_on_keys", unique: true
t.index ["translatable_type", "key", "value", "locale"], name: "index_mobility_string_translations_on_query_keys"
end现在,在您的控制台上,查找使用locale::de的记录
irb:> Post.all
irb:> Mobility::ActiveRecord::StringTranslation.where(locale: :de)正如您在schema.rb上看到的-> "mobility_string_translations“,您可以使用您的列来查找您想要的内容。
https://stackoverflow.com/questions/52520200
复制相似问题