저는 RoR이 처음입니다. 이 잘 작동 :레일즈 - collection_select는 번역이있는 테이블에서 값을 선택하지 않습니다.
<td><%= collection_select :competitions_members, :member_id, Member.all, :id, :first_name %></td>
이것은 하나의 값 (번역이있는 테이블에 실제로 이러한 모든 통화)을 선택합니다없는 : 회원이 많은 대회에 참여할 수
seeded data in competitions_members table
<td><%= collection_select :competitions_members, :tull_id, Tull.all, :id, :name %></td>
. 기본적으로 competencies_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
어떤 도움이 apreciated
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
관련 schema.db 발췌. 방금 번역 된 테이블과 연결될 수 있다는 것을 알았습니다.
Rails 5 ActiveRecord/AppplicationRecord와 관련된'translates' 지시어에 대한 참조를 찾을 수 없습니다. 다른 곳에서 온 것입니까? – Eric
'gem 'globalize', github : 'globalize/globalize ''를 사용하고 있습니다. 자세한 내용은 https://github.com/globalize/globalize에서 확인할 수 있습니다. –