1

in a app, I have the follow codes:

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

In my database, I have a table call name: user_profiles_knowledge_areas

How can I count and acess the records in this table?

I tried some options, like:

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

But anyone works, please, someone Can help me?

Sorry for my english, I'm learning yet

Lorena Bento
  • 544
  • 10
  • 29

1 Answers1

1

Your problem is you're calling UserProfile directly without initializing the object & populating with data:

users = User.find(:all)
for user in users do
    puts user.user_profile.knowledge_areas
end
Richard Peck
  • 76,116
  • 9
  • 93
  • 147