我对RoR比较新。 这工作得很好:Rails - collection_select不从具有翻译的表中选择值
<td><%= collection_select :competitions_members, :member_id, Member.all, :id, :first_name %></td>
这其中挑选没有价值(实际上翻译所有这些调用表):
<td><%= collection_select :competitions_members, :tull_id, Tull.all, :id, :name %></td>
seeded data in competitions_members table
会员可以在许多竞争有关。基本上,我通过比赛成员表在成员和比赛之间有N:M的关系。 Tull是一本字典。在分配成员参加比赛过程中设定的价值。
数据模型类:
class Member < ApplicationRecord
has_and_belongs_to_many :competitions
end
class Competition < ApplicationRecord
has_and_belongs_to_many :members
end
class CompetitionsMember < ApplicationRecord
end
Tull的表具有也是在单独的表中的翻译。
class Tull < ApplicationRecord
translates :name
has_many :competitions_members
# separate different localizations of the record
def cache_key
super + '-' + Globalize.locale.to_s
end
end
相关schema.db摘录
create_table "members", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "competitions", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "competitions_members", force: :cascade do |t|
t.integer "member_id"
t.integer "competition_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "tull_id"
t.index ["tull_id"], name: "index_competitions_members_on_tull_id"
end
create_table "tull_translations", force: :cascade do |t|
t.integer "tull_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.index ["locale"], name: "index_tull_translations_on_locale"
t.index ["tull_id"], name: "index_tull_translations_on_tull_id"
end
create_table "tulls", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
任何帮助apreciated。我只是意识到这可能会以某种方式与翻译表连接。
我找不到任何有关Rails 5 ActiveRecord/AppplicationRecord的'translates'指令的引用,它是否来自其他地方? – Eric
我正在使用gem'globalize',github:'globalize/globalize'。更多可以在这里找到 - https://github.com/globalize/globalize。 –