Я относительно новичок в 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 между участниками и соревнованиями через таблицу contest_members. 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. Я просто понял, что это может быть связано с переводимыми таблицами.
Я не могу найти ссылку на директиву 'translates' по отношению к Rails 5 ActiveRecord/AppplicationRecord, откуда она взята? – Eric
Я использую 'gem 'globalize', github: 'globalize/globalize''. Подробнее можно найти здесь - https://github.com/globalize/globalize. –