私はRoRが比較的新しいです。 これはうまく動作します:Rails - collection_selectは変換テーブルを持つテーブルから値を選択しません
<td><%= collection_select :competitions_members, :member_id, Member.all, :id, :first_name %></td>
この1が値(翻訳付きのテーブルに、実際にそのようなすべてのコールを)選ぶん:
<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
タルテーブルも別のテーブルの翻訳があります。
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 –