我对 RoR 比较陌生。这很好用:
<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>
会员可以参与很多比赛。基本上,我通过 Competitions_members 表在成员和比赛之间建立了 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
任何帮助表示赞赏。我刚刚意识到这可能与翻译的表格有关。