2016-10-03 2 views
0

저는 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 발췌. 방금 번역 된 테이블과 연결될 수 있다는 것을 알았습니다.

+0

Rails 5 ActiveRecord/AppplicationRecord와 관련된'translates' 지시어에 대한 참조를 찾을 수 없습니다. 다른 곳에서 온 것입니까? – Eric

+0

'gem 'globalize', github : 'globalize/globalize ''를 사용하고 있습니다. 자세한 내용은 https://github.com/globalize/globalize에서 확인할 수 있습니다. –

답변

0
class Tull < ApplicationRecord  
    has_many :translations 
    translates :name, :fallbacks_for_empty_translations => true 
    attr_accessible :translations_attributes 
end 

봅니다 레일 콘솔에서 코드 아래 실행합니다 :

Tull.first.translations을 -이 연결이 올바르지 의미 당신에게 번역 기록을 제공합니다.

이제보기 측면에서 확인하십시오. 어떻게 다국어 항목에 대한 속성을 생성 하시겠습니까? globalize_accessors을 사용하는 것이 좋습니다.

코드베이스를 보내주십시오.

+0

감사합니다. 콘솔을 통해 테스트 한 클래스를 업데이트했으며 연관성은 정확합니다. - https://github.com/valasek/taekwondo/blob/master/app/models/tull.rb. 그러나 collection_select는 여전히 올바른 값을 표시하지 않습니다. 변환 된 값을 표시하지만 테이블에서 값을 선택하지는 않습니다. 방금 변환되지 않은 테이블에 대해서도 값을 선택하지 않는다는 것을 알았습니다. –