2014-03-26 2 views
1

에 join_table 사용 ACESS 수, 나는 다음과 코드가 내 데이터베이스에서가 어떻게 테이블의 속성은 모델 A 앱에서

class UserProfile < ActiveRecord::Base 
    belongs_to :user 
    has_and_belongs_to_many :knowledge_areas, join_table: 'user_profiles_knowledge_areas', order: 'identifier' 


class KnowledgeArea < ActiveRecord::Base 
    attr_accessible :identifier, :label_key 
    attr_readonly :identifier, :label_key 

을, 나는 테이블 호출 이름이 있습니다 user_profiles_knowledge_areas를

이 테이블의 레코드를 어떻게 계산하고 액세스 할 수 있습니까?

내가 좋아하는 몇 가지 옵션, 시도 :

<%= @teste = UserProfile.knowledge_areas.find(:all) %> 
<%= @a = UserProfile.user_profiles_knowledge_areas %> 

그러나 사람이, 누군가가 나를 도울 수 주시기 바랍니다 작품?

users = User.find(:all) 
for user in users do 
    puts user.user_profile.knowledge_areas 
end 

답변

1

귀하의 문제는 당신이 데이터를 채우는 오브젝트 &를 초기화하지 않고 직접 UserProfile를 호출하는 것입니다

내 영어 죄송합니다

, 난 아직 배우는 중이에요 , thanks =]

+0

와우, 덕분에 많이, 내가 이해 : –

+0

Np! 희망이 당신을 도왔습니다! –

관련 문제